Class: Nokogiri::XML::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/cocainum/overrides.rb

Constant Summary collapse

TYPENAMES =
{1=>'element',2=>'attribute',3=>'text',4=>'cdata',8=>'comment'}

Instance Method Summary collapse

Instance Method Details

#to_hashObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/cocainum/overrides.rb', line 31

def to_hash
  [name.to_sym, case TYPENAMES[node_type]
                  when 'element'
                    node = {}
                    attribute_nodes.each {|attr| node[attr.name.to_sym] = attr.value}
                    children.each {|chld|
                      c = chld.to_hash
                      node[c[0].to_sym] = c[1] unless c[1] == nil
                    }
                    node
                  when 'text'
                    text.strip.empty? ? nil : text.strip
                  else
                    nil
                end]
end