Class: SlackRubyBot::Commands::Support::Help
- Inherits:
-
Object
- Object
- SlackRubyBot::Commands::Support::Help
- Includes:
- Singleton
- Defined in:
- lib/slack-ruby-bot/commands/support/help.rb
Instance Attribute Summary collapse
-
#commands_help_attrs ⇒ Object
readonly
Returns the value of attribute commands_help_attrs.
Instance Method Summary collapse
- #bot_desc_and_commands ⇒ Object
- #capture_help(klass, &block) ⇒ Object
- #command_full_desc(name) ⇒ Object
- #find_command_help_attrs(name) ⇒ Object
-
#initialize ⇒ Help
constructor
A new instance of Help.
- #other_commands_descs ⇒ Object
Constructor Details
#initialize ⇒ Help
Returns a new instance of Help.
13 14 15 |
# File 'lib/slack-ruby-bot/commands/support/help.rb', line 13 def initialize @commands_help_attrs = [] end |
Instance Attribute Details
#commands_help_attrs ⇒ Object (readonly)
Returns the value of attribute commands_help_attrs.
11 12 13 |
# File 'lib/slack-ruby-bot/commands/support/help.rb', line 11 def commands_help_attrs @commands_help_attrs end |
Instance Method Details
#bot_desc_and_commands ⇒ Object
23 24 25 26 27 28 |
# File 'lib/slack-ruby-bot/commands/support/help.rb', line 23 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
17 18 19 20 21 |
# File 'lib/slack-ruby-bot/commands/support/help.rb', line 17 def capture_help(klass, &block) k = Commands::Support::Attrs.new(klass) k.instance_eval(&block) @commands_help_attrs << k end |
#command_full_desc(name) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/slack-ruby-bot/commands/support/help.rb', line 34 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 |
#find_command_help_attrs(name) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/slack-ruby-bot/commands/support/help.rb', line 43 def find_command_help_attrs(name) help_attrs = commands_help_attrs.find { |k| k.command_name == name } return help_attrs if help_attrs commands_help_attrs.each { |k| k.commands.each { |c| return c if c.command_name == name } } nil end |
#other_commands_descs ⇒ Object
30 31 32 |
# File 'lib/slack-ruby-bot/commands/support/help.rb', line 30 def other_commands_descs collect_name_and_desc(other_commands_help_attrs) end |