Class: IRC
- Inherits:
-
Object
- Object
- IRC
- Defined in:
- lib/on_irc.rb,
lib/on_irc/event.rb,
lib/on_irc/config.rb,
lib/on_irc/parser.rb,
lib/on_irc/sender.rb,
lib/on_irc/server.rb,
lib/on_irc/callback.rb,
lib/on_irc/commands.rb,
lib/on_irc/connection.rb
Defined Under Namespace
Modules: Commands, Parser Classes: Callback, Config, ConfigDSL, ConfigError, Connection, Event, Sender, Server, ServerConfig, ServerConfigDSL
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#handlers ⇒ Object
Returns the value of attribute handlers.
-
#servers ⇒ Object
Returns the value of attribute servers.
Instance Method Summary collapse
- #[](server_id) ⇒ Object
- #connect ⇒ Object
-
#initialize(&block) ⇒ IRC
constructor
A new instance of IRC.
- #on(event, &block) ⇒ Object
- #send_cmd(server_id, cmd, *args) ⇒ Object
Constructor Details
#initialize(&block) ⇒ IRC
Returns a new instance of IRC.
10 11 12 13 14 15 16 17 |
# File 'lib/on_irc.rb', line 10 def initialize(&block) @config = ConfigDSL.run(&block) @servers = {} @config.servers.each do |server_id, server_conf| @servers[server_id] = Server.new(self, server_id, server_conf) end @handlers = {} end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
7 8 9 |
# File 'lib/on_irc.rb', line 7 def config @config end |
#handlers ⇒ Object
Returns the value of attribute handlers.
7 8 9 |
# File 'lib/on_irc.rb', line 7 def handlers @handlers end |
#servers ⇒ Object
Returns the value of attribute servers.
7 8 9 |
# File 'lib/on_irc.rb', line 7 def servers @servers end |
Instance Method Details
#[](server_id) ⇒ Object
23 24 25 |
# File 'lib/on_irc.rb', line 23 def [](server_id) servers[server_id] end |
#connect ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/on_irc.rb', line 31 def connect EventMachine.run do servers.values.each do |server| server.connection = EM.connect(server.address, server.port, Connection, server) end end end |
#on(event, &block) ⇒ Object
19 20 21 |
# File 'lib/on_irc.rb', line 19 def on(event, &block) @handlers[event.to_s.downcase.to_sym] = Callback.new(block) end |
#send_cmd(server_id, cmd, *args) ⇒ Object
27 28 29 |
# File 'lib/on_irc.rb', line 27 def send_cmd(server_id, cmd, *args) servers[server_id].send_cmd(cmd, *args) end |