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
9 10 11 12 |
# File 'lib/messagefactory/Factory.rb', line 9 def initialize @handlers = {} @lock = Splib::Monitor.new 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
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/messagefactory/Factory.rb', line 37 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
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/messagefactory/Factory.rb', line 16 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 |