class BubBot::Slack::CommandParser

Public Class Methods

command_classes() click to toggle source
# 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) click to toggle source
# 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