Class: XmlParsable::Elements::XmlElement::Node

Inherits:
AbstractElement show all
Defined in:
lib/xmlparsable/elements/xml.rb

Direct Known Subclasses

TextElement

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractElement

parsable

Constructor Details

#initialize(name, attributes, parent, *arguments) ⇒ Node

Returns a new instance of Node.



16
17
18
# File 'lib/xmlparsable/elements/xml.rb', line 16

def initialize(name, attributes, parent, *arguments)
  @parent, @name, @attributes, @children = parent, name, attributes, Array.new
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



14
15
16
# File 'lib/xmlparsable/elements/xml.rb', line 14

def attributes
  @attributes
end

#childrenObject (readonly)

Returns the value of attribute children.



14
15
16
# File 'lib/xmlparsable/elements/xml.rb', line 14

def children
  @children
end

#nameObject (readonly)

Returns the value of attribute name.



14
15
16
# File 'lib/xmlparsable/elements/xml.rb', line 14

def name
  @name
end

#parentObject (readonly)

Returns the value of attribute parent.



14
15
16
# File 'lib/xmlparsable/elements/xml.rb', line 14

def parent
  @parent
end

Instance Method Details

#close(element, value) ⇒ Object



32
33
34
# File 'lib/xmlparsable/elements/xml.rb', line 32

def close(element, value)
  @children << value
end

#comment(text) ⇒ Object



28
29
30
# File 'lib/xmlparsable/elements/xml.rb', line 28

def comment(text)
  @children << Comment.new(text, self)
end

#finalizeObject



36
37
38
# File 'lib/xmlparsable/elements/xml.rb', line 36

def finalize
  @parent.close(self, self)
end

#open(name, attributes) ⇒ Object



20
21
22
# File 'lib/xmlparsable/elements/xml.rb', line 20

def open(name, attributes)
  Node.new(name, attributes, self)
end

#read(text) ⇒ Object



24
25
26
# File 'lib/xmlparsable/elements/xml.rb', line 24

def read(text)
  @children << Text.new(text, self)
end

#to_s(buffer = "") ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/xmlparsable/elements/xml.rb', line 40

def to_s(buffer = "")
  buffer << "<#{@name}"
  @attributes.each{|name, value| buffer << %[ #{name}='#{value}'] }

  if @children.empty?
    buffer << "/>"
  else
    buffer << ">"
    @children.each{|child| child.to_s(buffer) }
    buffer << "</#{@name}>" 
  end
end