Class: Attentive::Listener
- Inherits:
-
Object
- Object
- Attentive::Listener
- Defined in:
- lib/attentive/listener.rb
Instance Attribute Summary collapse
-
#phrases ⇒ Object
readonly
Returns the value of attribute phrases.
Instance Method Summary collapse
- #call(e) ⇒ Object
-
#initialize(listeners, phrases, options, callback) ⇒ Listener
constructor
A new instance of Listener.
- #matches_context?(message) ⇒ Boolean
- #stop_listening! ⇒ Object
Constructor Details
#initialize(listeners, phrases, options, callback) ⇒ Listener
Returns a new instance of Listener.
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/attentive/listener.rb', line 8 def initialize(listeners, phrases, , callback) = .fetch(:context, {}) @required_contexts = .fetch(:in, Attentive.default_required_contexts) @required_contexts = [] if @required_contexts == :any @required_contexts = Set[*@required_contexts] @prohibited_contexts = .fetch(:not_in, Attentive.default_prohibited_contexts) @prohibited_contexts = Set[*@prohibited_contexts] @listeners = listeners @phrases = tokenize_phrases!(phrases) @callback = callback end |
Instance Attribute Details
#phrases ⇒ Object (readonly)
Returns the value of attribute phrases.
6 7 8 |
# File 'lib/attentive/listener.rb', line 6 def phrases @phrases end |
Instance Method Details
#call(e) ⇒ Object
32 33 34 |
# File 'lib/attentive/listener.rb', line 32 def call(e) @callback.call(e) end |
#matches_context?(message) ⇒ Boolean
21 22 23 24 25 |
# File 'lib/attentive/listener.rb', line 21 def matches_context?() return false unless .contexts.superset? @required_contexts return false unless .contexts.disjoint? @prohibited_contexts true end |
#stop_listening! ⇒ Object
27 28 29 30 |
# File 'lib/attentive/listener.rb', line 27 def stop_listening! listeners.delete self self end |