Class: Sponge::IRC::Listeners
- Inherits:
-
Object
- Object
- Sponge::IRC::Listeners
- Defined in:
- lib/sponge/irc/listeners.rb
Overview
Author
-
Lee Jarvis
Defined Under Namespace
Classes: Listener, ListenerExistsError
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
The IRC::Client using this Listener List.
Instance Method Summary collapse
- #[](command) ⇒ Object
-
#add(*commands, &blk) ⇒ Object
Add a new Listener to the Listener List * See IRC::Client#on.
- #all ⇒ Object
- #clear ⇒ Object
-
#delete(command) ⇒ Object
Remove a listener from our list.
-
#handle(message) ⇒ Object
Invoke #call on a Listener if it exists passing an IRC::Message.
- #include?(k) ⇒ Boolean
-
#initialize(client) ⇒ Listeners
constructor
A new instance of Listeners.
Constructor Details
#initialize(client) ⇒ Listeners
Returns a new instance of Listeners.
30 31 32 33 34 35 36 |
# File 'lib/sponge/irc/listeners.rb', line 30 def initialize(client) @client = client @list = {} # Add the default PING reply add(:PING) {|i, m| i.pong(m.text) } end |
Instance Attribute Details
#client ⇒ Object (readonly)
The IRC::Client using this Listener List
28 29 30 |
# File 'lib/sponge/irc/listeners.rb', line 28 def client @client end |
Instance Method Details
#[](command) ⇒ Object
54 55 56 |
# File 'lib/sponge/irc/listeners.rb', line 54 def [](command) @list[command] end |
#add(*commands, &blk) ⇒ Object
Add a new Listener to the Listener List
-
See IRC::Client#on
40 41 42 43 44 45 46 47 |
# File 'lib/sponge/irc/listeners.rb', line 40 def add(*commands, &blk) commands.each do |command| command = command.to_s.downcase raise ListenerExistsError, "listener for #{command} already exists" if @list.key?(command) @list[command] = Listener.new(command, &blk) end commands end |
#all ⇒ Object
75 76 77 |
# File 'lib/sponge/irc/listeners.rb', line 75 def all @list end |
#clear ⇒ Object
62 63 64 |
# File 'lib/sponge/irc/listeners.rb', line 62 def clear @list.clear end |
#delete(command) ⇒ Object
Remove a listener from our list
50 51 52 |
# File 'lib/sponge/irc/listeners.rb', line 50 def delete(command) @list.delete(command.to_s.downcase) end |
#handle(message) ⇒ Object
Invoke #call on a Listener if it exists passing an IRC::Message
67 68 69 70 71 72 73 |
# File 'lib/sponge/irc/listeners.rb', line 67 def handle() raise "Not a IRC::Message" unless .is_a?(Sponge::IRC::Message) command = .command.to_s.downcase if @list.key?(command) @list[command].call(client.irc, ) end end |
#include?(k) ⇒ Boolean
58 59 60 |
# File 'lib/sponge/irc/listeners.rb', line 58 def include?(k) @list.key?(k.to_s.downcase) end |