Class: AdobeShare::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/adobeshare/node.rb

Overview

Node Object Utility

Instance Method Summary collapse

Constructor Details

#initialize(node_xml) ⇒ Node

Returns a new instance of Node.



26
27
28
# File 'lib/adobeshare/node.rb', line 26

def initialize(node_xml)
  @xml = node_xml
end

Instance Method Details

#to_hashObject

Node elements (XML to Hash)



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/adobeshare/node.rb', line 31

def to_hash
  # FIXME
  # XXX
  # I Think it's not cool.
  # Maybe there is some good way to exchange from xml to hash...?
  doc = Document.new(@xml)
  node = Hash.new
  doc.elements["/response/node"].attributes.each{|k, v|
    node[k.to_sym] = v
  }
  if doc.elements["/response/children"]
    node[:children] = Array.new
    doc.elements["/response/children"].each{|e|
      child = Hash.new
      e.attributes.each{|k, v|
        child[k.to_sym] = v
      }
      node[:children] << child
    }
  end
  return node
end