Class: MessageFactory::Factory
- Inherits:
-
Object
- Object
- MessageFactory::Factory
- Defined in:
- lib/messagefactory/Factory.rb
Instance Method Summary collapse
-
#initialize ⇒ Factory
constructor
Create a new Factory.
-
#process(string, do_require = true) ⇒ Object
- string
-
String from IRC server to process Process the given string and return parsed message or nil.
-
#type(s) ⇒ Object
- s
-
string from server Determine type of message.
Constructor Details
#initialize ⇒ Factory
Create a new Factory
6 7 8 |
# File 'lib/messagefactory/Factory.rb', line 6 def initialize @handlers = {} end |
Instance Method Details
#process(string, do_require = true) ⇒ Object
- string
-
String from IRC server to process
Process the given string and return parsed message or nil
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/messagefactory/Factory.rb', line 33 def process(string, do_require=true) s = nil mtype = type(string) if(@handlers[mtype]) s = @handlers[mtype].process(string) else if(do_require) begin require "messagefactory/handlers/#{mtype}" load_handlers s = process(string, false) rescue LoadError s = mk_unknown(string) end else s = mk_unknown(string) end end s end |
#type(s) ⇒ Object
- s
-
string from server
Determine type of message
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/messagefactory/Factory.rb', line 12 def type(s) s = s.dup t = nil begin if(s.slice(0,1) == ':') s.slice!(0..s.index(' ')) t = s.slice!(0..s.index(' ')-1) else t = s.slice(0..s.index(' ')-1) end t.strip! rescue => e puts e raise 'Failed to determine message type' end t.to_sym end |