Module: ActiveSupport::XmlMini_Nokogiri::Conversions::Node

Defined in:
lib/active_support/xml_mini/nokogiri.rb

Constant Summary collapse

CONTENT_ROOT =
'__content__'

Instance Method Summary collapse

Instance Method Details

#attributes_as_hashObject



58
59
60
61
62
# File 'lib/active_support/xml_mini/nokogiri.rb', line 58

def attributes_as_hash
  Hash[*(attribute_nodes.map { |node|
    [node.node_name, node.value]
  }.flatten)]
end

#to_hash(hash = {}) ⇒ Object

Convert XML document to hash

hash

Hash to merge the converted element into.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/active_support/xml_mini/nokogiri.rb', line 35

def to_hash(hash = {})
  attributes = attributes_as_hash
  if hash[name]
    hash[name] = [hash[name]].flatten
    hash[name] << attributes
  else
    hash[name] ||= attributes
  end

  children.each { |child|
    next if child.blank? && 'file' != self['type']

    if child.text? || child.cdata?
      (attributes[CONTENT_ROOT] ||= '') << child.content
      next
    end

    child.to_hash attributes
  }

  hash
end