Class: Nokogiri::XML::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/taobao/xml_parser.rb

Instance Method Summary collapse

Instance Method Details

#to_symbolized_hashObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/taobao/xml_parser.rb', line 4

def to_symbolized_hash
  children.each_with_object({}) do |child, hash|
    key = child.name.to_sym
    if hash.has_key? key
      if Array === hash[key]
        hash[key] << child.value
      else
        hash[key] = [hash[key], child.value]
      end
    else
      hash[key] = child.value
    end
  end
end

#valueObject



18
19
20
21
22
23
24
# File 'lib/taobao/xml_parser.rb', line 18

def value
  if !children.empty? && Nokogiri::XML::Text === children[0]
    text
  else
    to_symbolized_hash
  end
end