Class: Ego::Listener
Overview
Listeners map user queries to handlers.
Instance Attribute Summary collapse
-
#handler ⇒ Object
Returns the value of attribute handler.
-
#parser ⇒ Object
Returns the value of attribute parser.
-
#pattern ⇒ Object
Returns the value of attribute pattern.
-
#priority ⇒ Object
Returns the value of attribute priority.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(pattern, priority, parser, handler) ⇒ Listener
constructor
A new instance of Listener.
- #match(query) ⇒ Object
Constructor Details
#initialize(pattern, priority, parser, handler) ⇒ Listener
Returns a new instance of Listener.
8 9 10 11 12 13 |
# File 'lib/ego/listener.rb', line 8 def initialize pattern, priority, parser, handler @pattern = pattern @priority = priority @parser = parser @handler = handler end |
Instance Attribute Details
#handler ⇒ Object
Returns the value of attribute handler.
6 7 8 |
# File 'lib/ego/listener.rb', line 6 def handler @handler end |
#parser ⇒ Object
Returns the value of attribute parser.
6 7 8 |
# File 'lib/ego/listener.rb', line 6 def parser @parser end |
#pattern ⇒ Object
Returns the value of attribute pattern.
6 7 8 |
# File 'lib/ego/listener.rb', line 6 def pattern @pattern end |
#priority ⇒ Object
Returns the value of attribute priority.
6 7 8 |
# File 'lib/ego/listener.rb', line 6 def priority @priority end |
Instance Method Details
#<=>(other) ⇒ Object
15 16 17 |
# File 'lib/ego/listener.rb', line 15 def <=> other @priority <=> other.priority end |
#match(query) ⇒ Object
19 20 21 22 23 |
# File 'lib/ego/listener.rb', line 19 def match query return false unless (matches = @pattern.match(query)) @parser.call matches end |