Class: Nokogiri::XML::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/ucslib/service/ucs/parser.rb

Constant Summary collapse

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

Instance Method Summary collapse

Instance Method Details

#to_hashObject



23
24
25
26
27
28
29
30
# File 'lib/ucslib/service/ucs/parser.rb', line 23

def to_hash
  {kind:TYPENAMES[node_type],name:name}.tap do |h|
    h.merge! nshref:namespace.href, nsprefix:namespace.prefix if namespace
    h.merge! text:text
    h.merge! attr:attribute_nodes.map(&:to_hash) if element?
    h.merge! kids:children.map(&:to_hash) if element?
  end
end