class Puree::XMLExtractor::Base

Base XML extractor.

Public Class Methods

new(xml) click to toggle source
# File lib/puree/xml_extractor/base.rb, line 9
def initialize(xml)
  make_doc xml
end

Public Instance Methods

xpath_query_for_multi_value(path) click to toggle source

XPath search for multiple values, at a given path.

@return [Array<String>]

# File lib/puree/xml_extractor/base.rb, line 24
def xpath_query_for_multi_value(path)
  xpath_result = xpath_query path
  arr = []
  xpath_result.each { |i| arr << i.text.strip }
  arr.uniq
end
xpath_query_for_single_value(path) click to toggle source

XPath search for a single value, at a given path.

@return [String, nil]

# File lib/puree/xml_extractor/base.rb, line 16
def xpath_query_for_single_value(path)
  xpath_result = xpath_query(path)
  xpath_result.empty? ? nil : xpath_result.first.text.strip
end

Private Instance Methods

make_doc(xml) click to toggle source
# File lib/puree/xml_extractor/base.rb, line 38
def make_doc(xml)
  @doc = Nokogiri::XML xml
  @doc.remove_namespaces!
end
setup_model(resource) click to toggle source
# File lib/puree/xml_extractor/base.rb, line 33
def setup_model(resource)
  resource_class = "Puree::Model::#{Puree::Util::String.titleize(resource)}"
  @model = Object.const_get(resource_class).new
end