Class: Boty::ActionDescription

Inherits:
Object
  • Object
show all
Defined in:
lib/boty/action_description.rb

Overview

Public: contains de descriptive information that was associated with an action via the ‘Bot#desc` method.

Besides that also keep tracks of the regex for the associated Action, it is used to describe the handler in case no command name and/or description was passed via ‘Bot#desc`.

The ‘ActionDescription` object will be stored inside the `Action#desc`. A good usage example can be found in the `scripts/knows.rb` script.

Examples:

# scripts/omg.rb
desc "X omg!", "Make the bot scream X omgs."
hear(/(\d+ )?omg!/i) do |how_many|
  how_many.times do say "LOL!" end
end

# => generates an action with a description like this:
ActionDescription.new "X omg!",
                      description: "Make the bot scream X omgs."
                      regex: /(\d+ )?omg!/i

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command, description: nil, regex: nil) ⇒ ActionDescription

Returns a new instance of ActionDescription.



28
29
30
31
32
33
34
35
36
37
# File 'lib/boty/action_description.rb', line 28

def initialize(command, description: nil, regex: nil)
  if description.nil?
    @description = command
  else
    @command = command
    @description = description
  end

  @regex = regex
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



25
26
27
# File 'lib/boty/action_description.rb', line 25

def command
  @command
end

#descriptionObject (readonly)

Returns the value of attribute description.



25
26
27
# File 'lib/boty/action_description.rb', line 25

def description
  @description
end

#regex=(value) ⇒ Object (writeonly)

Sets the attribute regex

Parameters:

  • value

    the value to set the attribute regex to.



26
27
28
# File 'lib/boty/action_description.rb', line 26

def regex=(value)
  @regex = value
end