Class: Puree::XMLExtractor::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/puree/xml_extractor/base.rb

Overview

Base XML extractor.

Direct Known Subclasses

Resource

Instance Method Summary collapse

Constructor Details

#initialize(xml) ⇒ Base

Returns a new instance of Base.



9
10
11
# File 'lib/puree/xml_extractor/base.rb', line 9

def initialize(xml)
  make_doc xml
end

Instance Method Details

#xpath_query_for_multi_value(path) ⇒ Array<String>

XPath search for multiple values, at a given path.

Returns:

  • (Array<String>)


24
25
26
27
28
29
# 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) ⇒ String?

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

Returns:

  • (String, nil)


16
17
18
19
# 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