Class: Peachy::Parsers::NokogiriWrapper

Inherits:
ParserWrapper show all
Defined in:
lib/peachy/parsers/nokogiri_wrapper.rb

Instance Method Summary collapse

Methods inherited from ParserWrapper

#create_from_element

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

Returns:

  • (Boolean)


25
26
27
# File 'lib/peachy/parsers/nokogiri_wrapper.rb', line 25

def has_children_and_attributes?
  has_children? and has_attributes?
end