Module: NodeHash

Included in:
LibXML::Conversions::Node, XmlMini_Nokogiri::Conversions::Node
Defined in:
lib/xml_mini/node_hash.rb

Constant Summary collapse

CONTENT_ROOT =
'__content__'.freeze

Instance Method Summary collapse

Instance Method Details

#handle_child_element(child, node_hash) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/xml_mini/node_hash.rb', line 15

def handle_child_element(child, node_hash)
  if child.element?
    child.to_hash(node_hash)
  elsif child.text? || child.cdata?
    node_hash[CONTENT_ROOT] ||= ''
    node_hash[CONTENT_ROOT] << child.content
  end
end

#insert_node_hash_into_parent(hash, name, node_hash) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'lib/xml_mini/node_hash.rb', line 4

def insert_node_hash_into_parent(hash, name, node_hash)
  case hash[name]
    when Array then
      hash[name] << node_hash
    when Hash then
      hash[name] = [hash[name], node_hash]
    when nil then
      hash[name] = node_hash
  end
end

#remove_blank_content_node(node_hash) ⇒ Object



24
25
26
27
28
# File 'lib/xml_mini/node_hash.rb', line 24

def remove_blank_content_node(node_hash)
  if node_hash.length > 1 && node_hash[CONTENT_ROOT].blank?
    node_hash.delete(CONTENT_ROOT)
  end
end