Class: Ego::Listener

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/ego/listener.rb

Overview

Listeners map user queries to handlers.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#handlerObject

Returns the value of attribute handler.



6
7
8
# File 'lib/ego/listener.rb', line 6

def handler
  @handler
end

#parserObject

Returns the value of attribute parser.



6
7
8
# File 'lib/ego/listener.rb', line 6

def parser
  @parser
end

#patternObject

Returns the value of attribute pattern.



6
7
8
# File 'lib/ego/listener.rb', line 6

def pattern
  @pattern
end

#priorityObject

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