Class: TextProtocols::Protocol
- Inherits:
-
Object
- Object
- TextProtocols::Protocol
- Defined in:
- lib/text_protocols.rb
Instance Attribute Summary collapse
-
#commands ⇒ Object
readonly
Returns the value of attribute commands.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
- #cmd(name, &block) ⇒ Object
- #handle(command, params) ⇒ Object
-
#initialize ⇒ Protocol
constructor
A new instance of Protocol.
Constructor Details
#initialize ⇒ Protocol
Returns a new instance of Protocol.
79 80 81 |
# File 'lib/text_protocols.rb', line 79 def initialize @commands = {} end |
Instance Attribute Details
#commands ⇒ Object (readonly)
Returns the value of attribute commands.
77 78 79 |
# File 'lib/text_protocols.rb', line 77 def commands @commands end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
77 78 79 |
# File 'lib/text_protocols.rb', line 77 def params @params end |
Instance Method Details
#cmd(name, &block) ⇒ Object
83 84 85 |
# File 'lib/text_protocols.rb', line 83 def cmd name, &block commands[name.upcase] = block end |
#handle(command, params) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 |
# 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 |