Sha256: fa4d8a12a5cc556d4a5eefb6882546471174e7ff4d24993da5762ffc0d9b2423

Contents?: true

Size: 1.16 KB

Versions: 12

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

module PageMagic
  # Builder for creating ElementDefinitions
  class ElementDefinitionBuilder
    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

    # 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>]
    def build(browser_element)
      query.execute(browser_element) do |result|
        definition_class.new(result)
      end
    end

    def ==(other)
      return false unless other.is_a?(ElementDefinitionBuilder)

      this = [query, definition_class]
      this == [other.send(:query), other.send(:definition_class)]
    end

    private

    attr_reader :query, :definition_class
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
page_magic-2.0.13 lib/page_magic/element_definition_builder.rb
page_magic-2.0.12 lib/page_magic/element_definition_builder.rb
page_magic-2.0.11 lib/page_magic/element_definition_builder.rb
page_magic-2.0.10 lib/page_magic/element_definition_builder.rb
page_magic-2.0.9 lib/page_magic/element_definition_builder.rb
page_magic-2.0.6 lib/page_magic/element_definition_builder.rb
page_magic-2.0.5 lib/page_magic/element_definition_builder.rb
page_magic-2.0.4 lib/page_magic/element_definition_builder.rb
page_magic-2.0.3 lib/page_magic/element_definition_builder.rb
page_magic-2.0.2 lib/page_magic/element_definition_builder.rb
page_magic-2.0.1 lib/page_magic/element_definition_builder.rb
page_magic-2.0.0 lib/page_magic/element_definition_builder.rb