Method: Facebooker::Parser.hashinate

Defined in:
lib/facebooker/parser.rb

.hashinate(response_element) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/facebooker/parser.rb', line 91

def self.hashinate(response_element)
  response_element.children.reject{|c| c.text? }.inject({}) do |hash, child|
    # If the node hasn't any child, and is not a list, we want empty strings, not empty hashes,
    #   except if attributes['nil'] == true
    hash[child.name] =
    if (child['nil'] == 'true')
      nil
    elsif (child.children.size == 1 && child.children.first.text?) || (child.children.size == 0 && child['list'] != 'true')
      anonymous_field_from(child, hash) || child.content.strip
    elsif child['list'] == 'true'
      child.children.reject{|c| c.text? }.map { |subchild| hash_or_value_for(subchild)}
    else
      child.children.reject{|c| c.text? }.inject({}) do |subhash, subchild|
        subhash[subchild.name] = hash_or_value_for(subchild)
        subhash
      end
    end #if (child.attributes)
    hash
  end #do |hash, child|
end