Sha256: a8f7576a862fd1258abb2b9c60c8f9a05e504aa681d6df2ac61c4833c72631bb

Contents?: true

Size: 933 Bytes

Versions: 11

Compression:

Stored size: 933 Bytes

Contents

# frozen_string_literal: true

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

11 entries across 11 versions & 1 rubygems

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