Sha256: 0c1bc600468df3f6a8a0ca72871fe2e16bba00acd48d7f2401bd0baf000ff8c9
Contents?: true
Size: 960 Bytes
Versions: 2
Compression:
Stored size: 960 Bytes
Contents
module CiviCrm class XML class << self def parse(text) doc = Nokogiri::XML.parse(text.to_s.gsub("\n", '')) results = doc.xpath('//Result') results.map do |result| hash = {} result.children.each do |attribute| next unless attribute.is_a?(Nokogiri::XML::Element) hash[attribute.name] = attribute.children[0].text rescue nil end hash end end def encode(resources) builder = Nokogiri::XML::Builder.new do |xml| xml.ResultSet do Array.wrap(resources).each do |resource| attributes = resource.respond_to?(:attributes) ? resource.attributes : resource xml.Result do attributes.each do |key, value| xml.send key.to_sym, value end end end end end builder.to_xml end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
civicrm-1.0.2 | lib/civicrm/xml.rb |
civicrm-1.0.1 | lib/civicrm/xml.rb |