Class: DYI::Shape::GraphicalTemplate
- Inherits:
-
Base
- Object
- Element
- GraphicalElement
- Base
- DYI::Shape::GraphicalTemplate
- 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.
Constant Summary collapse
- IMPLEMENT_ATTRIBUTES =
[:view_box, :preserve_aspect_ratio]
Constants inherited from GraphicalElement
GraphicalElement::CLASS_REGEXP
Constants inherited from Element
Instance Attribute Summary collapse
-
#child_elements ⇒ Array<Element>
readonly
Returns an array of child elements.
-
#metadata ⇒ Object
Returns a metadata object that the image has.
Attributes inherited from Base
#anchor_href, #anchor_target, #clipping, #parent
Attributes inherited from GraphicalElement
Attributes inherited from Element
Instance Method Summary collapse
-
#attributes ⇒ Hash
Returns optional attributes.
-
#initialize(width, height, preserve_aspect_ratio = 'none', options = {}) ⇒ GraphicalTemplate
constructor
A new instance of GraphicalTemplate.
- #instantiate_on(parent, left_top, options = {}) ⇒ Object
-
#root_element? ⇒ Boolean
Returns whether this instance is root element of the shape.
-
#write_as(formatter, io = $>) ⇒ Object
Writes image on io object.
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.
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', ={}) self.width = width self.height = height @view_box = "0 0 #{width} #{height}" @preserve_aspect_ratio = preserve_aspect_ratio @child_elements = [] self.css_class = [:css_class] end |
Instance Attribute Details
#child_elements ⇒ Array<Element> (readonly)
Returns an array of child elements.
52 53 54 |
# File 'lib/dyi/shape/graphical_template.rb', line 52 def child_elements @child_elements end |
#metadata ⇒ Object
Returns a metadata object that the image has.
56 57 58 |
# File 'lib/dyi/shape/graphical_template.rb', line 56 def @metadata end |
Instance Method Details
#attributes ⇒ Hash
Returns optional attributes.
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
90 91 92 |
# File 'lib/dyi/shape/graphical_template.rb', line 90 def instantiate_on(parent, left_top, ={}) Shape::ReusedShape.new(self, left_top, ).draw_on(parent) end |
#root_element? ⇒ Boolean
Returns whether this instance is root element of the shape.
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.
86 87 88 |
# File 'lib/dyi/shape/graphical_template.rb', line 86 def write_as(formatter, io=$>) formatter.write_template(self, io) end |