Class: Matchers::XML::XPathContainsText
- Inherits:
-
Object
- Object
- Matchers::XML::XPathContainsText
- Defined in:
- lib/matchers/xml/xpath_contains_text.rb
Instance Method Summary collapse
-
#initialize(xpath_expr_s, search_term) ⇒ XPathContainsText
constructor
A new instance of XPathContainsText.
- #matches?(document_s) ⇒ Boolean
Constructor Details
#initialize(xpath_expr_s, search_term) ⇒ XPathContainsText
Returns a new instance of XPathContainsText.
20 21 22 23 |
# 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 |
Instance Method Details
#matches?(document_s) ⇒ Boolean
26 27 28 29 30 31 32 |
# 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 |