class RForce::SoapResponseNokogiri
Public Class Methods
new(content)
click to toggle source
# File lib/rforce/soap_response_nokogiri.rb, line 5 def initialize(content) @content = content end
Public Instance Methods
parse()
click to toggle source
# File lib/rforce/soap_response_nokogiri.rb, line 9 def parse doc = Nokogiri::XML(@content) body = doc.at_xpath("//soapenv:Body") to_hash(body) end
Private Instance Methods
boolean(string)
click to toggle source
# File lib/rforce/soap_response_nokogiri.rb, line 55 def boolean(string) string == "true" end
boolean?(string)
click to toggle source
# File lib/rforce/soap_response_nokogiri.rb, line 59 def boolean?(string) %w{true false}.include?(string) end
parse_text(text)
click to toggle source
# File lib/rforce/soap_response_nokogiri.rb, line 47 def parse_text(text) text.strip! return nil if text.empty? boolean?(text) ? boolean(text) : text end
to_hash(node)
click to toggle source
# File lib/rforce/soap_response_nokogiri.rb, line 17 def to_hash(node) return parse_text(text) if node.text? children = node.children.reject {|c| c.text? && c.text.strip.empty? } return nil if children.empty? if (child = children.first).text? return parse_text(child.text) end elements = MethodHash.new children.each do |elem| name = elem.name.split(":").last.to_sym if !elements[name] # anything inside 'records' should be an array elements[name] = elem.name == 'records' ? [to_hash(elem)] : to_hash(elem) elsif Array === elements[name] elements[name] << to_hash(elem) else next if elem.name == "Id" # Id fields are duplicated elements[name] = [elements[name]] << to_hash(elem) end end return elements.empty? ? nil : elements end