Module: Scale::Node

Includes:
Enumerable
Included in:
Circle, Ellipse, 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



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

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

#append_to(builder) ⇒ Object



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

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

#childrenObject



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

def children
  @children ||= []
end

#eachObject



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

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

#to_xmlObject



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

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

#xml_attributesObject



38
39
40
# File 'lib/scale/node.rb', line 38

def xml_attributes
  attributes.delete_if { |key, value| value.nil? }
end