Sha256: 603fdc5c0d1f0c0bea9879e18be2166ad50544cd28945abe8c5c50f5d4f3a19f

Contents?: true

Size: 1.02 KB

Versions: 16

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

require 'aranha/dom_elements_traverser/conditions'
require 'aranha/dom_elements_traverser/data'
require 'aranha/dom_elements_traverser/cursor'

module Aranha
  class DomElementsTraverser
    include ::Aranha::DomElementsTraverser::Conditions
    include ::Aranha::DomElementsTraverser::Cursor
    include ::Aranha::DomElementsTraverser::Data

    class << self
      def traverse(options, &block)
        new(elements_from_options(options), &block)
      end

      def empty
        new([])
      end

      private

      def elements_from_options(options)
        options = ::EacRubyUtils::OptionsConsumer.new(options)
        elements = nil
        options.consume(:children_of) { |v| elements = v.children.to_a }
        raise 'None option of [:children_of] defined' unless elements

        options.validate
        elements
      end
    end

    private

    def initialize(elements, &block)
      @elements = elements
      @index = 0
      @data = {}
      instance_eval(&block) if block
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
aranha-0.14.5 lib/aranha/dom_elements_traverser.rb
aranha-0.14.4 lib/aranha/dom_elements_traverser.rb
aranha-0.14.3 lib/aranha/dom_elements_traverser.rb
aranha-0.14.2 lib/aranha/dom_elements_traverser.rb
aranha-0.14.1 lib/aranha/dom_elements_traverser.rb
aranha-0.14.0 lib/aranha/dom_elements_traverser.rb
aranha-0.13.1 lib/aranha/dom_elements_traverser.rb
aranha-0.13.0 lib/aranha/dom_elements_traverser.rb
aranha-0.12.1 lib/aranha/dom_elements_traverser.rb
aranha-0.12.0 lib/aranha/dom_elements_traverser.rb
aranha-0.11.2 lib/aranha/dom_elements_traverser.rb
aranha-0.11.1 lib/aranha/dom_elements_traverser.rb
aranha-0.11.0 lib/aranha/dom_elements_traverser.rb
aranha-0.10.1 lib/aranha/dom_elements_traverser.rb
aranha-0.10.0 lib/aranha/dom_elements_traverser.rb
aranha-0.9.1 lib/aranha/dom_elements_traverser.rb