class Matchers::XML::XPathContainsText

Public Class Methods

new(xpath_expr_s, search_term) click to toggle source

@param xpath_expr_s [String] - the XPath expression @param search_term [String | Regexp] - the search term

# File lib/matchers/xml/xpath_contains_text.rb, line 20
def initialize(xpath_expr_s, search_term)
  @xpath_expr_s = xpath_expr_s
  @search_term = search_term
end

Public Instance Methods

matches?(document_s) click to toggle source

@param document_s [String] - the XML document given as String

# File lib/matchers/xml/xpath_contains_text.rb, line 26
def matches?(document_s)
  xml_doc = REXML::Document.new(document_s)
  xpath = REXML::XPath.first(xml_doc, @xpath_expr_s)
  return false if xpath.nil?
  return @search_term.match(xpath.text) if @search_term.class == Regexp
  xpath.text.include?(@search_term)
end