Class: NOMS::XmlHash
Instance Attribute Summary collapse
-
#element ⇒ Object
Returns the value of attribute element.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(el) ⇒ XmlHash
constructor
A new instance of XmlHash.
- #to_xml(name = nil) ⇒ Object
Methods inherited from Hash
Constructor Details
#initialize(el) ⇒ XmlHash
Returns a new instance of XmlHash.
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/noms/httpclient.rb', line 48 def initialize(el) super @element = el @name = el.name self['text'] = el.text el.attributes.each do |attr, value| self[attr] = value end self['children'] = [] el.elements.each do |child| self['children'] << NOMS::XmlHash.new(child) end end |
Instance Attribute Details
#element ⇒ Object
Returns the value of attribute element.
46 47 48 |
# File 'lib/noms/httpclient.rb', line 46 def element @element end |
#name ⇒ Object
Returns the value of attribute name.
46 47 48 |
# File 'lib/noms/httpclient.rb', line 46 def name @name end |
Instance Method Details
#to_xml(name = nil) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/noms/httpclient.rb', line 62 def to_xml(name=nil) el = REXML::Element.new(name || self.name) el.text = self['text'] if self.has_key? 'text' self.each do |key, val| next if ['children', 'text'].include? key el.add_attribute(key, val) end if self.has_key? 'children' self['children'].each do |child| el.add_element child.to_xml end end el end |