Class: Marta::SimpleElementFinder::BasicFinder

Inherits:
Object
  • Object
show all
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

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?

Returns:

  • (Boolean)


29
30
31
# File 'lib/marta/simple_element_finder.rb', line 29

def collection?
  @meth['options']['collection']
end

#findObject

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?

Returns:

  • (Boolean)


34
35
36
# File 'lib/marta/simple_element_finder.rb', line 34

def forced_xpath?
  !@meth['options']['xpath'].nil?
end

#prefindObject

element prefinding



48
49
50
# File 'lib/marta/simple_element_finder.rb', line 48

def prefind
  @engine.element(xpath: @xpath)
end

#prefind_collectionObject

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_methObject

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