Sha256: 379bb34e77d983e98fbb5f88f7fa884d33049c30ebc57f09e77d44b5e28a5605
Contents?: true
Size: 639 Bytes
Versions: 15
Compression:
Stored size: 639 Bytes
Contents
class Hashify ## # Return a Hash from a Nokogiri::XML::Document. # # +node+: An Nokogiri::XML::Document. def self.convert node children = {} child_nodes = node.children if child_nodes.first.nil? children = nil elsif child_nodes.first.text? children = child_nodes.first.text else child_nodes.each do |child| convert(child).each_pair do |k, v| children[k] = if children.key? k children[k].is_a?(Array) ? (children[k] << v) : ([children[k], v]) else v end end end end { node.name => children } end end
Version data entries
15 entries across 15 versions & 1 rubygems