Class: XmlParsable::Elements::XmlElement::Node
- Inherits:
-
AbstractElement
- Object
- AbstractElement
- XmlParsable::Elements::XmlElement::Node
- Defined in:
- lib/xmlparsable/elements/xml.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Instance Method Summary collapse
- #close(element, value) ⇒ Object
- #comment(text) ⇒ Object
- #finalize ⇒ Object
-
#initialize(name, attributes, parent, *arguments) ⇒ Node
constructor
A new instance of Node.
- #open(name, attributes) ⇒ Object
- #read(text) ⇒ Object
- #to_s(buffer = "") ⇒ Object
Methods inherited from AbstractElement
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
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
14 15 16 |
# File 'lib/xmlparsable/elements/xml.rb', line 14 def attributes @attributes end |
#children ⇒ Object (readonly)
Returns the value of attribute children.
14 15 16 |
# File 'lib/xmlparsable/elements/xml.rb', line 14 def children @children end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
14 15 16 |
# File 'lib/xmlparsable/elements/xml.rb', line 14 def name @name end |
#parent ⇒ Object (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 |
#finalize ⇒ Object
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 |