Class: MessageFactory::Factory
- Inherits:
-
Object
- Object
- MessageFactory::Factory
- Defined in:
- lib/Factory.rb
Instance Method Summary collapse
-
#initialize ⇒ Factory
constructor
Create a new Factory.
-
#process(string) ⇒ 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
4 5 6 |
# File 'lib/Factory.rb', line 4 def initialize @handers = {} end |
Instance Method Details
#process(string) ⇒ Object
- string
-
String from IRC server to process
Process the given string and return parsed message or nil
30 31 32 33 34 35 36 37 38 |
# File 'lib/Factory.rb', line 30 def process(string) s = nil if(@handlers[type(string)]) s = @handlers.process(string) else raise NoMethodError.new("No handler found to process string: #{string}") end s end |
#type(s) ⇒ Object
- s
-
string from server
Determine type of message
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/Factory.rb', line 10 def type(s) s = s.dup t = nil begin if(s.slice(0,1).chr == ':') s.slice!(0..s.index(' ')) t = s.slice!(0..s.index(' ')-1) else t = s.slice(0..s.index(' ')-1) end t.strip! rescue raise 'Failed to determine message type' end t end |