Class: Puree::XMLExtractor::Base

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

Overview

Base XML extractor.

Direct Known Subclasses

Collection, Download, Resource, Server

Instance Method Summary collapse

Constructor Details

#initialize(xml:) ⇒ Base

Returns a new instance of Base.



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

def initialize(xml:)
  @api_map = Puree::API::Map.new.get
  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>)


25
26
27
28
29
30
# File 'lib/puree/xml_extractor/base.rb', line 25

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)


17
18
19
20
# File 'lib/puree/xml_extractor/base.rb', line 17

def xpath_query_for_single_value(path)
  xpath_result = xpath_query(path).text.strip
  xpath_result.empty? ? nil : xpath_result
end