Sha256: a96ed57ce225e2c8a55db016d71181cf9b155de57f7976ccea130f61af4ac5eb

Contents?: true

Size: 976 Bytes

Versions: 16

Compression:

Stored size: 976 Bytes

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/options_consumer'

module Aranha
  class DomElementsTraverser
    module Cursor
      private

      def current
        @elements[@index]
      end

      def skip
        @index += 1
      end

      def skip_until(options)
        oc = ::EacRubyUtils::OptionsConsumer.new(options)
        optional = oc.consume(:optional, false)
        while current
          break if match_conditions?(oc.left_data)

          skip
        end
        raise "No element found for conditions #{oc.left_data}" unless current || optional

        current
      end

      def skip_until_after(conditions)
        skip_until(conditions)
        skip
        current
      end

      def if_found(conditions, &block)
        marked = @index
        skip_until({ optional: true }.merge(conditions))
        if current
          instance_eval(&block) if block
        else
          @index = marked
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

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