class BotBrain::Commands::Command

Attributes

name[R]

Public Class Methods

new(name) click to toggle source
# File lib/bot_brain/commands/command.rb, line 6
def initialize(name)
  @name = name
  @alias = name
end

Public Instance Methods

answer(message) click to toggle source
# File lib/bot_brain/commands/command.rb, line 16
def answer(message)
  @args = parse_args(message.text)
  return help_full if @args == '?'

  process(message)
end
can_answer?(message) click to toggle source
# File lib/bot_brain/commands/command.rb, line 11
def can_answer?(message)
  data = name_regexp.match(message.text)
  !!data && data.length > 0
end
help() click to toggle source
# File lib/bot_brain/commands/command.rb, line 23
def help
  "#{name} - #{description}\n"
end

Private Instance Methods

description() click to toggle source
# File lib/bot_brain/commands/command.rb, line 33
def description
  'No description, this is abstract command'
end
example() click to toggle source
# File lib/bot_brain/commands/command.rb, line 37
def example
  'No example, this is abstract command'
end
help_full() click to toggle source
# File lib/bot_brain/commands/command.rb, line 41
def help_full
  "#{help}\nExample:\n#{example}"
end
name_regexp() click to toggle source
# File lib/bot_brain/commands/command.rb, line 50
def name_regexp
  @name_regexp ||= Regexp.new("\\A#{name}")
end
parse_args(text) click to toggle source
# File lib/bot_brain/commands/command.rb, line 45
def parse_args(text)
  return if text.nil?
  text.sub(name_regexp, '').strip
end
process(message) click to toggle source
# File lib/bot_brain/commands/command.rb, line 29
def process(message)
  message.text
end