Class: BotBrain::Dictionary

Inherits:
Object
  • Object
show all
Defined in:
lib/bot_brain/dictionary.rb

Instance Method Summary collapse

Constructor Details

#initialize(commands, unknown_command = nil) ⇒ Dictionary

Returns a new instance of Dictionary.



3
4
5
6
# File 'lib/bot_brain/dictionary.rb', line 3

def initialize(commands, unknown_command = nil)
  @commands = commands
  @unknown_command = unknown_command || Commands::UnknownCommand.new
end

Instance Method Details

#get_command(message) ⇒ Object



8
9
10
11
# File 'lib/bot_brain/dictionary.rb', line 8

def get_command(message)
  command = @commands.detect { |c| c.can_answer?(message) }
  command || @unknown_command
end