Sha256: aa16b11ab3042433184f8b5ad924a1f9ba28d51bd81939428ed84df38b1a1cb3
Contents?: true
Size: 1010 Bytes
Versions: 4
Compression:
Stored size: 1010 Bytes
Contents
require 'nokogiri' module RForce class SoapResponseNokogiri def initialize(content) @content = content end def parse doc = Nokogiri::XML(@content) body = doc.at_xpath("//soapenv:Body") to_hash(body) end private def to_hash(node) if node.text? stripped = node.text.strip return stripped.empty? ? nil : stripped end children = node.children.reject {|c| c.text? && c.text.strip.empty? } return nil if children.empty? return children.first.text.strip if children.first.text? elements = MethodHash.new children.each do |elem| name = elem.name.split(":").last.to_sym if !elements[name] elements[name] = to_hash(elem) elsif Array === elements[name] elements[name] << to_hash(elem) else elements[name] = [elements[name]] << to_hash(elem) end end return elements.empty? ? nil : elements end end end
Version data entries
4 entries across 4 versions & 1 rubygems