Class: Sponge::IRC::Parser
- Inherits:
-
Object
- Object
- Sponge::IRC::Parser
- Defined in:
- lib/sponge/irc/parser.rb
Overview
Defined Under Namespace
Classes: BadMessageFormat
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Our IRC::Client instance.
Instance Method Summary collapse
-
#initialize(client) ⇒ Parser
constructor
A new instance of Parser.
-
#parse(data) ⇒ Object
Parses a raw IRC server message and returns a nicely encapsulated IRC::Message for you to play with.
Constructor Details
#initialize(client) ⇒ Parser
Returns a new instance of Parser.
18 19 20 |
# File 'lib/sponge/irc/parser.rb', line 18 def initialize(client) @client = client end |
Instance Attribute Details
#client ⇒ Object (readonly)
Our IRC::Client instance
16 17 18 |
# File 'lib/sponge/irc/parser.rb', line 16 def client @client end |
Instance Method Details
#parse(data) ⇒ Object
Parses a raw IRC server message and returns a nicely encapsulated IRC::Message for you to play with
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/sponge/irc/parser.rb', line 24 def parse(data) return unless data raise(BadMessageFormat, "Unknown Message") unless matches = data.match(/\A(?:\:(\S+)\s)?([A-Z0-9]+?)\s(.+?)\Z/) prefix, command, params = matches.captures = IRC::Message.new(client, data, prefix, command, params) .for = .params.first .text = .params.last if prefix && usermatch = prefix.match(/^(\S+?)!(\S+?)@(\S+?)$/) .from = IRC::User.new(client, *usermatch.captures) .nick = .from.nick end end |