Class: BubBot::Slack::CommandParser

Inherits:
Object
  • Object
show all
Defined in:
lib/bub_bot/slack/command_parser.rb

Class Method Summary collapse

Class Method Details

.command_classesObject



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/bub_bot/slack/command_parser.rb', line 26

def self.command_classes

  # Get all the classes under BubBot::Slack::Command::*
  @_command_classes ||= BubBot::Slack::Command.constants.map do |constant|
    (BubBot::Slack::Command.to_s + "::" + constant.to_s).safe_constantize
  end.select do |constant|

    # Get only the constants that are classes and inherit from Command
    constant.is_a?(Class) && constant < BubBot::Slack::Command
  end
end

.get_command(string_input) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/bub_bot/slack/command_parser.rb', line 8

def self.get_command(string_input)
  puts "Parsing #{string_input}"
  #puts "options: #{command_classes}"

  # Strip the bot name out
  string_input.sub!(/^#{BubBot.configuration.bot_name} /, '')

  command = string_input.split(' ').first

  if command
    command_classes.find do |command_class|
      command_class.can_handle?(command)
    end
  else
    nil
  end
end