Class: Attentive::Tokens::AnyOf

Inherits:
StringToken show all
Defined in:
lib/attentive/tokens/any_of.rb

Instance Attribute Summary collapse

Attributes inherited from StringToken

#string

Attributes inherited from Attentive::Token

#begin

Instance Method Summary collapse

Methods inherited from StringToken

#eql?, #hash, #length, #to_s, #to_str

Methods inherited from Attentive::Token

#end, #entity?, #eof?, #inspect, #skippable?, #whitespace?

Constructor Details

#initialize(string, possibilities, pos) ⇒ AnyOf

Returns a new instance of AnyOf.



8
9
10
11
# File 'lib/attentive/tokens/any_of.rb', line 8

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

Instance Attribute Details

#possibilitiesObject (readonly)

Returns the value of attribute possibilities.



6
7
8
# File 'lib/attentive/tokens/any_of.rb', line 6

def possibilities
  @possibilities
end

Instance Method Details

#==(other) ⇒ Object



13
14
15
# File 'lib/attentive/tokens/any_of.rb', line 13

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

#ambiguous?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/attentive/tokens/any_of.rb', line 17

def ambiguous?
  true
end

#matches?(cursor) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
24
25
26
27
28
29
30
31
# File 'lib/attentive/tokens/any_of.rb', line 21

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