Class: Baldrick::Listeners::XPathLocator
- Inherits:
-
Object
- Object
- Baldrick::Listeners::XPathLocator
- Defined in:
- lib/baldrick/listeners/xpath_locator.rb
Class Method Summary collapse
Instance Method Summary collapse
- #find_nodes_matching(*paths) ⇒ Object
- #find_text_matching(*paths) ⇒ Object
-
#initialize(node) ⇒ XPathLocator
constructor
A new instance of XPathLocator.
Constructor Details
#initialize(node) ⇒ XPathLocator
Returns a new instance of XPathLocator.
15 16 17 |
# File 'lib/baldrick/listeners/xpath_locator.rb', line 15 def initialize node @doc = node end |
Class Method Details
.from_node(node) ⇒ Object
11 12 13 |
# File 'lib/baldrick/listeners/xpath_locator.rb', line 11 def self.from_node node self.new node end |
.from_xml(xml) ⇒ Object
7 8 9 |
# File 'lib/baldrick/listeners/xpath_locator.rb', line 7 def self.from_xml xml from_node Nokogiri::XML(strip_default_namespaces_from(xml)) end |
Instance Method Details
#find_nodes_matching(*paths) ⇒ Object
24 25 26 |
# File 'lib/baldrick/listeners/xpath_locator.rb', line 24 def find_nodes_matching *paths @doc.search *paths || [] end |
#find_text_matching(*paths) ⇒ Object
19 20 21 22 |
# File 'lib/baldrick/listeners/xpath_locator.rb', line 19 def find_text_matching *paths matches = find_nodes_matching *paths matches.first.text unless matches.empty? end |