Class: Butler::IRC::Client::Listener

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/butler/irc/client/listener.rb

Overview

Created by Butler::IRC::Client#subscribe() and similar methods

Constant Summary collapse

AllSymbols =
[nil].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(symbols = nil, priority = 0, *args, &callback) ⇒ Listener

Returns a new instance of Listener.



22
23
24
25
26
27
28
# File 'lib/butler/irc/client/listener.rb', line 22

def initialize(symbols=nil, priority=0, *args, &callback)
	@priority  = priority
	@symbols   = (symbols ? Array(symbols) : AllSymbols).freeze
	@args      = args
	@callback  = callback
	@container = nil
end

Instance Attribute Details

#containerObject

Returns the value of attribute container.



20
21
22
# File 'lib/butler/irc/client/listener.rb', line 20

def container
  @container
end

#priorityObject

Returns the value of attribute priority.



18
19
20
# File 'lib/butler/irc/client/listener.rb', line 18

def priority
  @priority
end

#symbolsObject (readonly)

Returns the value of attribute symbols.



19
20
21
# File 'lib/butler/irc/client/listener.rb', line 19

def symbols
  @symbols
end

Instance Method Details

#<=>(other) ⇒ Object

Comparison is done by priority, higher priority comes first, so Listener.new(nil, -100) > Listener.new(nil, 100)



37
38
39
# File 'lib/butler/irc/client/listener.rb', line 37

def <=>(other)
	other.priority <=> @priority
end

#call(*args) ⇒ Object

Invoke the listener, always passes self as first argument



49
50
51
# File 'lib/butler/irc/client/listener.rb', line 49

def call(*args)
	@callback.call(self, *(args+@args))
end

#unsubscribeObject

will remove this listener from the clients dispatcher forever



31
32
33
# File 'lib/butler/irc/client/listener.rb', line 31

def unsubscribe
	@container.unsubscribe(self)
end