Created
March 31, 2013 02:20
-
-
Save reppard/5279215 to your computer and use it in GitHub Desktop.
eval freakout?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MessageHandler | |
MSG_TYPES = { 'NOTICE' => 'NOTICE', | |
'372' => 'RPL_MOTD' | |
} | |
def process(line) | |
MSG_TYPES.each do |code, type| | |
line.match(code) ? eval("MessageHandler::#{type}::output(code,line)") : puts line | |
end | |
end | |
module NOTICE | |
def self.output(code,line) | |
msg = parse(code,line) | |
puts "\e[32m#{msg}\e[0m" | |
end | |
def self.parse(code,line) | |
line.gsub(/^.*\s(#{code})/,"[#{Time.now.ctime.gsub(/\d+$/,"")}]") | |
end | |
end | |
module RPL_MOTD | |
def self.output(code,line) | |
msg = parse(code,line) | |
puts "\e[31m#{msg}\e[0m" | |
end | |
def self.parse(code,line) | |
line.gsub(/^.*\s(#{code})/,"[#{Time.now.ctime.gsub(/\d+$/,"")}]") | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment