Class: BotBrain::Commands::Command

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

Direct Known Subclasses

UnknownCommand

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Command

Returns a new instance of Command.



6
7
8
9
# File 'lib/bot_brain/commands/command.rb', line 6

def initialize(name)
  @name = name
  @alias = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/bot_brain/commands/command.rb', line 4

def name
  @name
end

Instance Method Details

#answer(message) ⇒ Object



16
17
18
19
20
21
# 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) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
# File 'lib/bot_brain/commands/command.rb', line 11

def can_answer?(message)
  data = name_regexp.match(message.text)
  !!data && data.length > 0
end

#helpObject



23
24
25
# File 'lib/bot_brain/commands/command.rb', line 23

def help
  "#{name} - #{description}\n"
end