Skip to content

Instantly share code, notes, and snippets.

@reppard
Created March 31, 2013 02:20
Show Gist options
  • Save reppard/5279215 to your computer and use it in GitHub Desktop.
Save reppard/5279215 to your computer and use it in GitHub Desktop.
eval freakout?
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