class Ant::Bot::Command

Object that wraps a command, it is analogus to a route definition. it currently only gets a param list, but it will be extended to a more complex DSL.

Public Class Methods

new(params, block) click to toggle source

Receives a list of params as symbols and the lambda with the block.

# File lib/ant/bot/command_definition.rb, line 10
def initialize(params, block)
  @params = params
  @block = block
end

Public Instance Methods

execute(params) click to toggle source

Calls the block with the params list. Fails if there is a missing param

# File lib/ant/bot/command_definition.rb, line 16
def execute(params)
  raise 'NotReady' unless ready?(params)

  @block.call(params)
end
next_missing_param(current_params) click to toggle source

Finds the first empty param from the given parameter

# File lib/ant/bot/command_definition.rb, line 28
def next_missing_param(current_params)
  @params.find { |key| !current_params.key?(key) }
end
ready?(current_params) click to toggle source

Checks if the params object given contains all the needed values

# File lib/ant/bot/command_definition.rb, line 23
def ready?(current_params)
  @params.all? { |key| current_params.key?(key) }
end