class TextProtocols::Protocol

Attributes

commands[R]
params[R]

Public Class Methods

new() click to toggle source
# File lib/text_protocols.rb, line 79
def initialize
  @commands = {}
end

Public Instance Methods

cmd(name, &block) click to toggle source
# File lib/text_protocols.rb, line 83
def cmd name, &block
  commands[name.upcase] = block
end
handle(command, params) click to toggle source
# File lib/text_protocols.rb, line 87
def handle command, params
  block = commands[command.chomp.upcase]
  return "UNKNOW" if block.nil?
  
  if params
    @params = params
  else
    @params = {}
  end
  
  block.call
end