Class: SlackRubyBot::CommandsHelper

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/slack-ruby-bot/support/commands_helper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCommandsHelper

Returns a new instance of CommandsHelper.



9
10
11
# File 'lib/slack-ruby-bot/support/commands_helper.rb', line 9

def initialize
  @commands_help_attrs = []
end

Instance Attribute Details

#commands_help_attrsObject (readonly)

Returns the value of attribute commands_help_attrs.



7
8
9
# File 'lib/slack-ruby-bot/support/commands_helper.rb', line 7

def commands_help_attrs
  @commands_help_attrs
end

Instance Method Details

#bot_desc_and_commandsObject



19
20
21
22
23
24
# File 'lib/slack-ruby-bot/support/commands_helper.rb', line 19

def bot_desc_and_commands
  collect_help_attrs(bot_help_attrs) do |help_attrs|
    bot_commands_descs = collect_name_and_desc(help_attrs.commands)
    "#{command_name_and_desc(help_attrs)}\n\n*Commands:*\n#{bot_commands_descs.join("\n")}"
  end
end

#capture_help(klass, &block) ⇒ Object



13
14
15
16
17
# File 'lib/slack-ruby-bot/support/commands_helper.rb', line 13

def capture_help(klass, &block)
  k = Commands::Help::Attrs.new(klass)
  k.instance_eval(&block)
  @commands_help_attrs << k
end

#command_full_desc(name) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/slack-ruby-bot/support/commands_helper.rb', line 30

def command_full_desc(name)
  unescaped_name = Slack::Messages::Formatting.unescape(name)
  help_attrs = find_command_help_attrs(unescaped_name)
  return "There's no command *#{unescaped_name}*" unless help_attrs
  return "There's no description for command *#{unescaped_name}*" if help_attrs.command_long_desc.blank?
  "#{command_name_and_desc(help_attrs)}\n\n#{help_attrs.command_long_desc}"
end

#other_commands_descsObject



26
27
28
# File 'lib/slack-ruby-bot/support/commands_helper.rb', line 26

def other_commands_descs
  collect_name_and_desc(other_commands_help_attrs)
end