Class: PageMagic::ElementDefinitionBuilder
- Inherits:
-
Object
- Object
- 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.
-
#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 |
# 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 @options = @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 |
#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
32 33 34 35 36 |
# File 'lib/page_magic/element_definition_builder.rb', line 32 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
28 29 30 |
# File 'lib/page_magic/element_definition_builder.rb', line 28 def build(browser_element) definition_class.new(browser_element) end |