Sha256: 87ddf3e2ca503ac82cf4f09e2b0cc8e64f58b318d3b5751b897bce523f2bc4eb

Contents?: true

Size: 745 Bytes

Versions: 8

Compression:

Stored size: 745 Bytes

Contents

require "attentive/token"

module Attentive
  module Tokens
    class AnyOf < StringToken
      attr_reader :possibilities

      def initialize(string, possibilities, pos)
        super string, pos
        @possibilities = possibilities
      end

      def ==(other)
        self.class == other.class && self.possibilities == other.possibilities
      end

      def ambiguous?
        true
      end

      def matches?(cursor)
        possibilities.each do |phrase|
          cursor_copy = cursor.new_from_here
          match = Attentive::Matcher.new(phrase, cursor_copy).match!
          if match
            cursor.advance cursor_copy.pos
            return match.to_h
          end
        end
        false
      end

    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
attentive-0.3.9 lib/attentive/tokens/any_of.rb
attentive-0.3.8 lib/attentive/tokens/any_of.rb
attentive-0.3.7 lib/attentive/tokens/any_of.rb
attentive-0.3.6 lib/attentive/tokens/any_of.rb
attentive-0.3.5 lib/attentive/tokens/any_of.rb
attentive-0.3.4 lib/attentive/tokens/any_of.rb
attentive-0.3.3 lib/attentive/tokens/any_of.rb
attentive-0.3.2 lib/attentive/tokens/any_of.rb