Class: PageMagic::ElementDefinitionBuilder
- Defined in:
- lib/page_magic/element_definition_builder.rb
Overview
Builder for creating ElementDefinitions
Constant Summary collapse
- INVALID_SELECTOR_MSG =
'Pass a locator/define one on the class'.freeze
Instance Attribute Summary collapse
-
#definition_class ⇒ Object
readonly
Returns the value of attribute definition_class.
-
#element ⇒ Object
readonly
Returns the value of attribute element.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#query_builder ⇒ Object
readonly
Returns the value of attribute query_builder.
-
#selector ⇒ Object
readonly
Returns the value of attribute selector.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#build(browser_element) ⇒ Element
Create new instance of the ElementDefinition modeled by this builder.
-
#build_query ⇒ Capybara::Query
Query to find this element in the browser.
-
#initialize(definition_class:, selector:, type:, options: {}, element: nil) ⇒ ElementDefinitionBuilder
constructor
A new instance of ElementDefinitionBuilder.
Constructor Details
#initialize(definition_class:, selector:, type:, options: {}, element: nil) ⇒ ElementDefinitionBuilder
Returns a new instance of ElementDefinitionBuilder.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/page_magic/element_definition_builder.rb', line 7 def initialize(definition_class:, selector:, type:, options: {}, element: nil) unless element selector ||= definition_class.selector raise UndefinedSelectorException, INVALID_SELECTOR_MSG if selector.nil? || selector.empty? end @definition_class = definition_class @selector = selector @type = type @query_builder = Element::QueryBuilder.find(type) @options = { multiple_results: false }.merge() @element = element end |
Instance Attribute Details
#definition_class ⇒ Object (readonly)
Returns the value of attribute definition_class.
5 6 7 |
# File 'lib/page_magic/element_definition_builder.rb', line 5 def definition_class @definition_class end |
#element ⇒ Object (readonly)
Returns the value of attribute element.
5 6 7 |
# File 'lib/page_magic/element_definition_builder.rb', line 5 def element @element end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/page_magic/element_definition_builder.rb', line 5 def @options end |
#query_builder ⇒ Object (readonly)
Returns the value of attribute query_builder.
5 6 7 |
# File 'lib/page_magic/element_definition_builder.rb', line 5 def query_builder @query_builder end |
#selector ⇒ Object (readonly)
Returns the value of attribute selector.
5 6 7 |
# File 'lib/page_magic/element_definition_builder.rb', line 5 def selector @selector end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
5 6 7 |
# File 'lib/page_magic/element_definition_builder.rb', line 5 def type @type end |
Instance Method Details
#==(other) ⇒ Object
35 36 37 38 39 |
# File 'lib/page_magic/element_definition_builder.rb', line 35 def ==(other) return false unless other.is_a?(ElementDefinitionBuilder) this = [, selector, type, element, definition_class] this == [other., other.selector, other.type, other.element, other.definition_class] end |
#build(browser_element) ⇒ Element
Create new instance of the ElementDefinition modeled by this builder
31 32 33 |
# File 'lib/page_magic/element_definition_builder.rb', line 31 def build(browser_element) definition_class.new(browser_element) end |
#build_query ⇒ Capybara::Query
Returns query to find this element in the browser.
23 24 25 26 |
# File 'lib/page_magic/element_definition_builder.rb', line 23 def build_query multiple_results = .delete(:multiple_results) query_builder.build(selector, , multiple_results: multiple_results) end |