Class: Matchers::XML::DocumentContainsXPath

Inherits:
Object
  • Object
show all
Defined in:
lib/matchers/xml/document_contains_xpath.rb

Instance Method Summary collapse

Constructor Details

#initialize(xpath_expr_s, occurrences = 1) ⇒ DocumentContainsXPath

Returns a new instance of DocumentContainsXPath.

Parameters:

  • xpath_expr_s (String)
    • the XPath expression

  • optional

    occurences [Integer] - the number of occurences expected in document



22
23
24
25
# File 'lib/matchers/xml/document_contains_xpath.rb', line 22

def initialize(xpath_expr_s, occurrences = 1)
  @xpath_expr_s = xpath_expr_s
  @occurrences = occurrences
end

Instance Method Details

#matches?(document_s) ⇒ Boolean

Parameters:

  • document_s (String)
    • the document given as String

Returns:

  • (Boolean)


28
29
30
31
32
# File 'lib/matchers/xml/document_contains_xpath.rb', line 28

def matches?(document_s)
  xml_doc = REXML::Document.new(document_s)
  nodes = REXML::XPath.match(xml_doc, @xpath_expr_s)
  nodes.count >= @occurrences
end