Class: Puree::XMLExtractor::Base
- Inherits:
-
Object
- Object
- Puree::XMLExtractor::Base
- Defined in:
- lib/puree/xml_extractor/base.rb
Overview
Base XML extractor.
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize(xml) ⇒ Base
constructor
A new instance of Base.
-
#xpath_query_for_multi_value(path) ⇒ Array<String>
XPath search for multiple values, at a given path.
-
#xpath_query_for_single_value(path) ⇒ String?
XPath search for a single value, at a given path.
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.
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.
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 |