Class: Attentive::Tokens::AnyOf
- Inherits:
-
StringToken
- Object
- Attentive::Token
- StringToken
- Attentive::Tokens::AnyOf
- Defined in:
- lib/attentive/tokens/any_of.rb
Instance Attribute Summary collapse
-
#possibilities ⇒ Object
readonly
Returns the value of attribute possibilities.
Attributes inherited from StringToken
Attributes inherited from Attentive::Token
Instance Method Summary collapse
- #==(other) ⇒ Object
- #ambiguous? ⇒ Boolean
-
#initialize(string, possibilities, pos) ⇒ AnyOf
constructor
A new instance of AnyOf.
- #matches?(cursor) ⇒ Boolean
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
#possibilities ⇒ Object (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
17 18 19 |
# File 'lib/attentive/tokens/any_of.rb', line 17 def ambiguous? true end |
#matches?(cursor) ⇒ 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 |