module WorldpayCnp::XML::Parser

Public Instance Methods

call(xml) click to toggle source
# File lib/worldpay_cnp/xml/parser.rb, line 4
def call(xml)
  hash_with(root(xml))
end

Private Instance Methods

hash_with(*nodes) click to toggle source
# File lib/worldpay_cnp/xml/parser.rb, line 18
def hash_with(*nodes)
  nodes.each_with_object({}) do |node, hash|
    inject_or_merge!(hash, node.name, value_with!(node))
  end
end
inject_or_merge!(hash, key, value) click to toggle source
# File lib/worldpay_cnp/xml/parser.rb, line 24
def inject_or_merge!(hash, key, value)
  if hash.key?(key)
    cv = hash[key]
    value = cv.is_a?(Array) ? cv.push(value) : [cv, value]
  end
  hash[key] = value
end
root(xml) click to toggle source
# File lib/worldpay_cnp/xml/parser.rb, line 10
def root(xml)
  raise NotImplementedError
end
value_with!(element) click to toggle source
# File lib/worldpay_cnp/xml/parser.rb, line 14
def value_with!(element)
  raise NotImplementedError
end