Class: CommandBot::CommandCall

Inherits:
Object
  • Object
show all
Defined in:
lib/command_bot/command_call.rb

Overview

Stores command call information.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bot, text, data) ⇒ CommandCall

New command call.



10
11
12
13
14
15
16
17
18
# File 'lib/command_bot/command_call.rb', line 10

def initialize(bot, text, data)
  @bot = bot
  @text = text
  @data = data

  @command = nil
  @arguments = []
  @options = {}
end

Instance Attribute Details

#argumentsArray<String>



33
34
35
# File 'lib/command_bot/command_call.rb', line 33

def arguments
  @arguments
end

#botBot (readonly)



21
22
23
# File 'lib/command_bot/command_call.rb', line 21

def bot
  @bot
end

#commandCommand?



30
31
32
# File 'lib/command_bot/command_call.rb', line 30

def command
  @command
end

#dataHash (readonly)



27
28
29
# File 'lib/command_bot/command_call.rb', line 27

def data
  @data
end

#optionsHash<String, String>



36
37
38
# File 'lib/command_bot/command_call.rb', line 36

def options
  @options
end

#textString (readonly)



24
25
26
# File 'lib/command_bot/command_call.rb', line 24

def text
  @text
end

Instance Method Details

#executevoid

This method returns an undefined value.

Executes command.



40
41
42
43
44
# File 'lib/command_bot/command_call.rb', line 40

def execute
  raise 'Command not identified!' if command.nil?

  command.handler.call(bot, arguments, options, data)
end

#to_sString



47
48
49
50
51
52
53
54
55
# File 'lib/command_bot/command_call.rb', line 47

def to_s
  if command.nil?
    "COMMAND_NOT_FOUND(`#{text}`)"
  else
    arg_str = arguments.join(', ')
    opt_str = options.map { |k, v| "#{k}: #{v}" }.join(', ')
    "#{command.name}[#{arg_str}]{#{opt_str}}"
  end
end