class DYI::Shape::GraphicalTemplate

The body of Vector-Image. This class is a container for all graphical elements that make up the image. @since 1.3.0

Constants

IMPLEMENT_ATTRIBUTES

@private

Attributes

child_elements[R]

Returns an array of child elements. @return [Array<Element>] an array of child elements

metadata[RW]

Returns a metadata object that the image has. @return [Object] a metadata object that the image has.

Public Class Methods

new(width, height, preserve_aspect_ratio='none', options={}) click to toggle source

@param [Length] width width of the canvas on user unit @param [Length] height height of the canvas on user unit @param [Length] real_width width of the image. When this value

is nil, uses a value that equals value of width parameter.

@param [Length] real_height height of the image. When this value

is nil, uses a value that equals value of height parameter.

@param [String] preserve_aspect_ratio value that indicates

whether or not to force uniform scaling

@option options [String] :css_class CSS class of body element

# File lib/dyi/shape/graphical_template.rb, line 66
def initialize(width, height,
               preserve_aspect_ratio='none', options={})
  self.width = width
  self.height = height
  @view_box = "0 0 #{width} #{height}"
  @preserve_aspect_ratio = preserve_aspect_ratio
  @child_elements = []
  self.css_class = options[:css_class]
end

Public Instance Methods

attributes() click to toggle source

Returns optional attributes. @return [Hash] optional attributes

# File lib/dyi/shape/graphical_template.rb, line 95
def attributes
  IMPLEMENT_ATTRIBUTES.inject({}) do |hash, attribute|
    variable_name = '@' + attribute.to_s.split(/(?=[A-Z])/).map{|str| str.downcase}.join('_')
    value = instance_variable_get(variable_name)
    hash[attribute] = value.to_s if value
    hash
  end
end
instantiate_on(parent, left_top, options={}) click to toggle source
# File lib/dyi/shape/graphical_template.rb, line 89
def instantiate_on(parent, left_top, options={})
  Shape::ReusedShape.new(self, left_top, options).draw_on(parent)
end
root_element?() click to toggle source

Returns whether this instance is root element of the shape. @return [Boolean] always true.

# File lib/dyi/shape/graphical_template.rb, line 78
def root_element?
  false
end
write_as(formatter, io=$>) click to toggle source

Writes image on io object. @param [Formatter::Base] formatter an object that defines the image format @param [IO] io an io to be written

# File lib/dyi/shape/graphical_template.rb, line 85
def write_as(formatter, io=$>)
  formatter.write_template(self, io)
end