Class: PageMagic::ElementDefinitionBuilder
- Defined in:
- lib/page_magic/element_definition_builder.rb
Overview
Builder for creating ElementDefinitions
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#build(browser_element) ⇒ Capybara::Node::Element+
Create new instance of the ElementDefinition modeled by this builder.
-
#initialize(definition_class:, selector:, query_class: PageMagic::Element::Query::SingleResult, element: nil) ⇒ ElementDefinitionBuilder
constructor
A new instance of ElementDefinitionBuilder.
Constructor Details
#initialize(definition_class:, selector:, query_class: PageMagic::Element::Query::SingleResult, element: nil) ⇒ ElementDefinitionBuilder
Returns a new instance of ElementDefinitionBuilder.
6 7 8 9 10 11 12 13 14 |
# File 'lib/page_magic/element_definition_builder.rb', line 6 def initialize(definition_class:, selector:, query_class: PageMagic::Element::Query::SingleResult, element: nil) @definition_class = definition_class @query = if element PageMagic::Element::Query::PrefetchedResult.new(element) else query_class.new(*selector.args, options: selector.) end end |
Instance Method Details
#==(other) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/page_magic/element_definition_builder.rb', line 26 def ==(other) return false unless other.is_a?(ElementDefinitionBuilder) this = [query, definition_class] this == [other.send(:query), other.send(:definition_class)] end |
#build(browser_element) ⇒ Capybara::Node::Element+
Create new instance of the ElementDefinition modeled by this builder
20 21 22 23 24 |
# File 'lib/page_magic/element_definition_builder.rb', line 20 def build(browser_element) query.execute(browser_element) do |result| definition_class.new(result) end end |