class PageMagic::ElementDefinitionBuilder

Builder for creating ElementDefinitions

Attributes

definition_class[R]
query[R]

Public Class Methods

new(definition_class:, selector:, query_class: PageMagic::Element::Query::SingleResult, element: nil) click to toggle source
# 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.options)
           end
end

Public Instance Methods

==(other) click to toggle source
# 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) click to toggle source

Create new instance of the ElementDefinition modeled by this builder @param [Object] browser_element capybara browser element corresponding to the element modelled by this builder @return [Capybara::Node::Element] @return [Array<Capybara::Node::Element>]

# 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