Sha256: e37db2eab92dc997b5175b45291505f877e3034fd0519b6b5fd3b7624ed00fee

Contents?: true

Size: 1.05 KB

Versions: 11

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

require_dependency 'aranha/dom_elements_traverser/conditions'
require_dependency 'aranha/dom_elements_traverser/data'
require_dependency '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

11 entries across 11 versions & 1 rubygems

Version Path
aranha-0.9.0 lib/aranha/dom_elements_traverser.rb
aranha-0.8.0 lib/aranha/dom_elements_traverser.rb
aranha-0.7.1 lib/aranha/dom_elements_traverser.rb
aranha-0.7.0 lib/aranha/dom_elements_traverser.rb
aranha-0.6.0 lib/aranha/dom_elements_traverser.rb
aranha-0.5.0 lib/aranha/dom_elements_traverser.rb
aranha-0.4.0 lib/aranha/dom_elements_traverser.rb
aranha-0.3.0 lib/aranha/dom_elements_traverser.rb
aranha-0.2.1 lib/aranha/dom_elements_traverser.rb
aranha-0.2.0 lib/aranha/dom_elements_traverser.rb
aranha-0.1.0 lib/aranha/dom_elements_traverser.rb