Class: PageMagic::Element::Selector
- Defined in:
- lib/page_magic/element/selector.rb,
lib/page_magic/element/selector/model.rb,
lib/page_magic/element/selector/methods.rb
Overview
class Selector - models the selection criteria understood by Capybara
Defined Under Namespace
Modules: Methods Classes: Model
Class Method Summary collapse
-
.find(name) ⇒ Selector
Find a Selector using it's name.
Instance Method Summary collapse
-
#build(element_type, locator, options: {}) ⇒ Object
Build selector query parameters for Capybara's find method.
-
#initialize(selector = nil, supports_type: false, exact: false, &formatter) ⇒ Selector
constructor
Initialize a new selector a block can be supplied to decorate the query.
Constructor Details
#initialize(selector = nil, supports_type: false, exact: false, &formatter) ⇒ Selector
Initialize a new selector a block can be supplied to decorate the query. E.g.
38 39 40 41 42 43 44 45 |
# File 'lib/page_magic/element/selector.rb', line 38 def initialize(selector = nil, supports_type: false, exact: false, &formatter) @selector = selector @formatter = formatter || proc { |arg| arg } @supports_type = supports_type = {}.tap do |hash| hash[:exact] = true if exact end end |
Class Method Details
.find(name) ⇒ Selector
Find a Selector using it's name
14 15 16 17 18 19 |
# File 'lib/page_magic/element/selector.rb', line 14 def find(name) selector_name = selector_constant_name(name) raise UnsupportedCriteriaException unless selector_name const_get(selector_name) end |
Instance Method Details
#build(element_type, locator, options: {}) ⇒ Object
Build selector query parameters for Capybara's find method
50 51 52 53 |
# File 'lib/page_magic/element/selector.rb', line 50 def build(element_type, locator, options: {}) array = [type(element_type), selector, formatter.call(locator)].compact Model.new(array, self..merge()) end |