Class: Issola::Command::Handler
- Inherits:
-
Object
- Object
- Issola::Command::Handler
- Defined in:
- lib/issola/command/handler.rb
Instance Method Summary collapse
- #handle(event) ⇒ Object
-
#initialize ⇒ Handler
constructor
A new instance of Handler.
- #register {|builder| ... } ⇒ Object
Constructor Details
#initialize ⇒ Handler
Returns a new instance of Handler.
4 5 6 |
# File 'lib/issola/command/handler.rb', line 4 def initialize @commands = {} end |
Instance Method Details
#handle(event) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/issola/command/handler.rb', line 18 def handle(event) tokens = event..content.split(' ') puts "Checking for command in message: #{ tokens.inspect }" # Get rid of command prefix key = tokens.first[1..-1] cmd = @commands[key] if cmd puts "Found command!" cmd.action.call(event) end end |
#register {|builder| ... } ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/issola/command/handler.rb', line 8 def register builder = Builder.new yield builder raise ArgumentError, 'Unable to register command, required attribute(s) missing.' unless builder.valid? cmd = builder.command @commands[cmd.key] = cmd end |