module TINCheck::XML::Parser

Public Instance Methods

call(xml) click to toggle source
# File lib/tincheck/xml/parser.rb, line 6
def call(xml)
  at_depth(3, hash_with(root(xml)))
end

Private Instance Methods

at_depth(num, hash) click to toggle source
# File lib/tincheck/xml/parser.rb, line 12
def at_depth(num, hash)
  return unless hash.is_a?(Hash)
  nh = hash.values.first
  num.zero? ? nh : at_depth(num - 1, nh)
end
hash_with(*nodes) click to toggle source
# File lib/tincheck/xml/parser.rb, line 18
def hash_with(*nodes)
  nodes.each_with_object({}) do |n, h|
    inject_or_merge!(h, n.name, value_with!(n))
  end
end
inject_or_merge!(hash, key, value) click to toggle source
# File lib/tincheck/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
text_or_nil(text) click to toggle source
# File lib/tincheck/xml/parser.rb, line 32
def text_or_nil(text)
  return if !text || text.empty? || text[0] == "\n"
  text
end