Class: CommandBot::CommandCall
- Inherits:
-
Object
- Object
- CommandBot::CommandCall
- Defined in:
- lib/command_bot/command_call.rb
Overview
Stores command call information.
Instance Attribute Summary collapse
- #arguments ⇒ Array<String>
- #bot ⇒ Bot readonly
-
#command ⇒ Command?
nilif command can’t be found. - #data ⇒ Hash readonly
- #options ⇒ Hash<String, String>
- #text ⇒ String readonly
Instance Method Summary collapse
-
#execute ⇒ void
Executes command.
-
#initialize(bot, text, data) ⇒ CommandCall
constructor
New command call.
- #to_s ⇒ String
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
#arguments ⇒ Array<String>
33 34 35 |
# File 'lib/command_bot/command_call.rb', line 33 def arguments @arguments end |
#command ⇒ Command?
Returns nil if command can’t be found.
30 31 32 |
# File 'lib/command_bot/command_call.rb', line 30 def command @command end |
#data ⇒ Hash (readonly)
27 28 29 |
# File 'lib/command_bot/command_call.rb', line 27 def data @data end |
#options ⇒ Hash<String, String>
36 37 38 |
# File 'lib/command_bot/command_call.rb', line 36 def @options end |
#text ⇒ String (readonly)
24 25 26 |
# File 'lib/command_bot/command_call.rb', line 24 def text @text end |
Instance Method Details
#execute ⇒ void
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, , data) end |
#to_s ⇒ String
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 = .map { |k, v| "#{k}: #{v}" }.join(', ') "#{command.name}[#{arg_str}]{#{opt_str}}" end end |