Class: DYI::Shape::GraphicalTemplate

Inherits:
Base show all
Defined in:
lib/dyi/shape/graphical_template.rb

Overview

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

Since:

  • 1.3.0

Constant Summary collapse

IMPLEMENT_ATTRIBUTES =

Since:

  • 1.3.0

[:view_box, :preserve_aspect_ratio]

Constants inherited from GraphicalElement

GraphicalElement::CLASS_REGEXP

Constants inherited from Element

Element::ID_REGEXP

Instance Attribute Summary collapse

Attributes inherited from Base

#anchor_href, #anchor_target, #clipping, #parent

Attributes inherited from GraphicalElement

#css_class

Attributes inherited from Element

#description, #title

Instance Method Summary collapse

Methods inherited from Base

#add_animation, #add_painting_animation, #add_transform_animation, #animate?, #animations, #clear_clipping, #draw_on, #has_marker?, #has_uri_reference?, #root_node?, #rotate, #scale, #set_clipping, #set_clipping_shapes, #set_event, #skew_x, #skew_y, #transform, #translate

Methods inherited from GraphicalElement

#add_css_class, #add_event_listener, #css_classes, #event_listeners, #event_target?, #remove_css_class, #remove_event_listener, #set_event, #to_reused_source

Methods inherited from Element

#canvas, #has_uri_reference?, #id, #id=, #include_external_file?, #inner_id

Constructor Details

#initialize(width, height, preserve_aspect_ratio = 'none', options = {}) ⇒ GraphicalTemplate

Returns a new instance of GraphicalTemplate.

Parameters:

  • width (Length)

    width of the canvas on user unit

  • height (Length)

    height of the canvas on user unit

  • real_width (Length)

    width of the image. When this value is nil, uses a value that equals value of width parameter.

  • real_height (Length)

    height of the image. When this value is nil, uses a value that equals value of height parameter.

  • preserve_aspect_ratio (String) (defaults to: 'none')

    value that indicates whether or not to force uniform scaling

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :css_class (String)

    CSS class of body element

Since:

  • 1.3.0



67
68
69
70
71
72
73
74
75
# File 'lib/dyi/shape/graphical_template.rb', line 67

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

Instance Attribute Details

#child_elementsArray<Element> (readonly)

Returns an array of child elements.

Returns:

  • (Array<Element>)

    an array of child elements

Since:

  • 1.3.0



52
53
54
# File 'lib/dyi/shape/graphical_template.rb', line 52

def child_elements
  @child_elements
end

#metadataObject

Returns a metadata object that the image has.

Returns:

  • (Object)

    a metadata object that the image has.

Since:

  • 1.3.0



56
57
58
# File 'lib/dyi/shape/graphical_template.rb', line 56

def 
  @metadata
end

Instance Method Details

#attributesHash

Returns optional attributes.

Returns:

  • (Hash)

    optional attributes

Since:

  • 1.3.0



96
97
98
99
100
101
102
103
# File 'lib/dyi/shape/graphical_template.rb', line 96

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 = {}) ⇒ Object

Since:

  • 1.3.0



90
91
92
# File 'lib/dyi/shape/graphical_template.rb', line 90

def instantiate_on(parent, left_top, options={})
  Shape::ReusedShape.new(self, left_top, options).draw_on(parent)
end

#root_element?Boolean

Returns whether this instance is root element of the shape.

Returns:

  • (Boolean)

    always true.

Since:

  • 1.3.0



79
80
81
# File 'lib/dyi/shape/graphical_template.rb', line 79

def root_element?
  false
end

#write_as(formatter, io = $>) ⇒ Object

Writes image on io object.

Parameters:

  • formatter (Formatter::Base)

    an object that defines the image format

  • io (IO) (defaults to: $>)

    an io to be written

Since:

  • 1.3.0



86
87
88
# File 'lib/dyi/shape/graphical_template.rb', line 86

def write_as(formatter, io=$>)
  formatter.write_template(self, io)
end