Class: Peachy::Parsers::NokogiriWrapper
- Inherits:
-
ParserWrapper
- Object
- ParserWrapper
- Peachy::Parsers::NokogiriWrapper
- Defined in:
- lib/peachy/parsers/nokogiri_wrapper.rb
Instance Method Summary collapse
- #find_match_by_attributes(method_name) ⇒ Object
-
#find_matches(method_name) ⇒ Object
Runs the XPath for the method name against the underlying XML DOM, returning nil if no element or attribute matching the method name is found in the children of the current location in the DOM.
- #has_children_and_attributes? ⇒ Boolean
-
#initialize(nokogiri) ⇒ NokogiriWrapper
constructor
A new instance of NokogiriWrapper.
Methods inherited from ParserWrapper
Constructor Details
#initialize(nokogiri) ⇒ NokogiriWrapper
Returns a new instance of NokogiriWrapper.
6 7 8 |
# File 'lib/peachy/parsers/nokogiri_wrapper.rb', line 6 def initialize nokogiri @nokogiri = nokogiri end |
Instance Method Details
#find_match_by_attributes(method_name) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/peachy/parsers/nokogiri_wrapper.rb', line 18 def find_match_by_attributes method_name match = @nokogiri.attribute_nodes.find do |attribute| attribute if method_name.variations.include? attribute.name end match.nil? ? nil : make_from(match) end |
#find_matches(method_name) ⇒ Object
Runs the XPath for the method name against the underlying XML DOM, returning nil if no element or attribute matching the method name is found in the children of the current location in the DOM.
13 14 15 16 |
# File 'lib/peachy/parsers/nokogiri_wrapper.rb', line 13 def find_matches method_name matches = xpath method_name.as_xpath matches.any? ? matches : nil end |
#has_children_and_attributes? ⇒ Boolean
25 26 27 |
# File 'lib/peachy/parsers/nokogiri_wrapper.rb', line 25 def has_children_and_attributes? has_children? and has_attributes? end |