Module: Scale::Node

Includes:
Enumerable
Included in:
Circle, Ellipse, Line, Path, Polygon, Polyline, Rectangle, SVG, Text
Defined in:
lib/scale/node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



7
8
9
# File 'lib/scale/node.rb', line 7

def content
  @content
end

Instance Method Details

#add(node) ⇒ Object



14
15
16
# File 'lib/scale/node.rb', line 14

def add(node)
  children.push(node)
end

#append_to(builder) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/scale/node.rb', line 31

def append_to(builder)
  builder.send(xml_tag.to_sym, *xml_parameters) do
    each do |node|
      node.append_to(builder)
    end
  end
end

#childrenObject



10
11
12
# File 'lib/scale/node.rb', line 10

def children
  @children ||= []
end

#eachObject



18
19
20
21
22
# File 'lib/scale/node.rb', line 18

def each
  children.each do |child|
    yield child
  end
end

#to_xmlObject



24
25
26
27
28
29
# File 'lib/scale/node.rb', line 24

def to_xml
  builder = Nokogiri::XML::Builder.new do |xml|
    append_to(xml)
  end
  builder.to_xml
end

#xml_attributesObject



39
40
41
42
43
44
45
# File 'lib/scale/node.rb', line 39

def xml_attributes
  attributes.inject({}) do |memo, (key, value)|
    new_key = key.to_s.gsub(/\_/, "-").to_sym
    memo[new_key] = value unless value.nil?
    memo
  end
end