Class: Attentive::ListenerCollection
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Attentive::ListenerCollection
- Defined in:
- lib/attentive/listener_collection.rb
Instance Method Summary collapse
- #hear(message) ⇒ Object
-
#initialize ⇒ ListenerCollection
constructor
A new instance of ListenerCollection.
- #listen_for(*args, &block) ⇒ Object
Constructor Details
#initialize ⇒ ListenerCollection
Returns a new instance of ListenerCollection.
11 12 13 |
# File 'lib/attentive/listener_collection.rb', line 11 def initialize super ThreadSafe::Array.new end |
Instance Method Details
#hear(message) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/attentive/listener_collection.rb', line 23 def hear() listeners = select { |listener| listener.matches_context?() } # Listen for any known phrase, starting with any token in the message. matches = [] .tokens.each_with_index do |token, i| listeners.each do |listener| listener.phrases.each do |phrase| match = Attentive::Matcher.new(phrase, Cursor.new(.tokens, i), listener: listener, message: ).match! next unless match # Don't match more than one phrase per listener matches.push match break end end end matches end |