Class: Marta::SimpleElementFinder::BasicFinder
- Inherits:
-
Object
- Object
- Marta::SimpleElementFinder::BasicFinder
- Includes:
- XPath
- Defined in:
- lib/marta/simple_element_finder.rb
Overview
Note:
It is believed that no user will use it
That class is about simle element location strategy
The main idea is not to find an element but to find an xpath that leads to a valid element.
Instance Method Summary collapse
-
#collection? ⇒ Boolean
Maybe our element is defined as a collection?.
-
#find ⇒ Object
Main logic.
-
#forced_xpath? ⇒ Boolean
Maybe our element has user provided xpath?.
-
#initialize(meth, requestor) ⇒ BasicFinder
constructor
A new instance of BasicFinder.
-
#prefind ⇒ Object
element prefinding.
-
#prefind_collection ⇒ Object
collection prefinding.
-
#subtype_of(element) ⇒ Object
Transforming an element to a subtype.
-
#xpath_by_meth ⇒ Object
Getting an xpath.
Constructor Details
#initialize(meth, requestor) ⇒ BasicFinder
Returns a new instance of BasicFinder.
21 22 23 24 25 26 |
# File 'lib/marta/simple_element_finder.rb', line 21 def initialize(meth, requestor) @requestor = requestor @meth = meth @xpath = xpath_by_meth if !@meth.nil? @engine = requestor.engine end |
Instance Method Details
#collection? ⇒ Boolean
Maybe our element is defined as a collection?
29 30 31 |
# File 'lib/marta/simple_element_finder.rb', line 29 def collection? @meth['options']['collection'] end |
#find ⇒ Object
Main logic. We are returning a prefinded collection or subtyped prefind
68 69 70 71 72 73 74 |
# File 'lib/marta/simple_element_finder.rb', line 68 def find if collection? prefind_collection else subtype_of prefind end end |
#forced_xpath? ⇒ Boolean
Maybe our element has user provided xpath?
34 35 36 |
# File 'lib/marta/simple_element_finder.rb', line 34 def forced_xpath? !@meth['options']['xpath'].nil? end |
#prefind ⇒ Object
element prefinding
48 49 50 |
# File 'lib/marta/simple_element_finder.rb', line 48 def prefind @engine.element(xpath: @xpath) end |
#prefind_collection ⇒ Object
collection prefinding
53 54 55 |
# File 'lib/marta/simple_element_finder.rb', line 53 def prefind_collection @engine.elements(xpath: @xpath) end |
#subtype_of(element) ⇒ Object
Transforming an element to a subtype
58 59 60 61 62 63 64 |
# File 'lib/marta/simple_element_finder.rb', line 58 def subtype_of(element) if @engine.element(xpath: @xpath).exists? @engine.element(xpath: @xpath).to_subtype else @engine.element(xpath: @xpath) end end |
#xpath_by_meth ⇒ Object
Getting an xpath
39 40 41 42 43 44 45 |
# File 'lib/marta/simple_element_finder.rb', line 39 def xpath_by_meth if forced_xpath? @meth['options']['xpath'] else XPathFactory.new(@meth, @requestor).generate_xpath end end |