Class: ModSpox::MessageFactory
- Inherits:
-
Object
- Object
- ModSpox::MessageFactory
- Defined in:
- lib/mod_spox/MessageFactory.rb
Instance Attribute Summary collapse
-
#handlers ⇒ Object
readonly
access to handlers.
Instance Method Summary collapse
-
#<<(string) ⇒ Object
- string
-
server message to be parsed Parses messages from server.
-
#find_key(s) ⇒ Object
- s
-
string from server determine type of message from server.
-
#initialize(pipeline, pool) ⇒ MessageFactory
constructor
- pipeline
-
Message pipeline Create a new MessageFactory.
Constructor Details
#initialize(pipeline, pool) ⇒ MessageFactory
- pipeline
-
Message pipeline
Create a new MessageFactory
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/mod_spox/MessageFactory.rb', line 14 def initialize(pipeline, pool) @pipeline = pipeline @pool = pool @sync_pool = ActionPool::Pool.new(1, 1, nil, 2, Logger.raw) @handlers = Hash.new build_handlers @sync = [RPL_MOTDSTART, RPL_MOTD, RPL_ENDOFMOTD, RPL_WHOREPLY, RPL_ENDOFWHO, RPL_NAMREPLY, RPL_ENDOFNAMES, RPL_WHOISUSER, RPL_WHOISSERVER, RPL_WHOISOPERATOR, RPL_WHOISIDLE, RPL_WHOISCHANNELS, RPL_WHOISIDENTIFIED, RPL_ENDOFWHOIS] end |
Instance Attribute Details
#handlers ⇒ Object (readonly)
access to handlers. (only really needed for testing)
10 11 12 |
# File 'lib/mod_spox/MessageFactory.rb', line 10 def handlers @handlers end |
Instance Method Details
#<<(string) ⇒ Object
- string
-
server message to be parsed
Parses messages from server. This is placed in a queue to be processed thus there is now wait for processing to be completed.
29 30 31 |
# File 'lib/mod_spox/MessageFactory.rb', line 29 def <<(string) @pool.process{ (string) } end |
#find_key(s) ⇒ Object
- s
-
string from server
determine type of message from server
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/mod_spox/MessageFactory.rb', line 35 def find_key(s) s = s.dup begin key = nil if(s[0].chr == ':') s.slice!(0..s.index(' ')) key = s.slice!(0..s.index(' ')-1) else key = s.slice(0..s.index(' ')-1) end key.strip! key = key.to_sym if key.to_i == 0 return key rescue Object Logger.info("Failed to find key for message: #{s}") raise Exceptions::UnknownKey.new end end |