class SlackRubyBot::Commands::Support::Help

Attributes

commands_help_attrs[R]

Public Class Methods

new() click to toggle source
# File lib/slack-ruby-bot/commands/support/help.rb, line 13
def initialize
  @commands_help_attrs = []
end

Public Instance Methods

bot_desc_and_commands() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# File lib/slack-ruby-bot/commands/support/help.rb, line 30
def other_commands_descs
  collect_name_and_desc(other_commands_help_attrs)
end

Private Instance Methods

bot_help_attrs() click to toggle source
# File lib/slack-ruby-bot/commands/support/help.rb, line 74
def bot_help_attrs
  commands_help_attrs.select { |k| k.klass.ancestors.include?(SlackRubyBot::Bot) }
end
collect_help_attrs(help_attrs) { |ha| ... } click to toggle source
# File lib/slack-ruby-bot/commands/support/help.rb, line 53
def collect_help_attrs(help_attrs)
  help_attrs_with_present_names(help_attrs).map do |ha|
    yield(ha)
  end
end
collect_name_and_desc(help_attrs) click to toggle source
# File lib/slack-ruby-bot/commands/support/help.rb, line 59
def collect_name_and_desc(help_attrs)
  collect_help_attrs(help_attrs) do |ha|
    command_name_and_desc(ha)
  end
end
command_name_and_desc(help_attrs) click to toggle source
# File lib/slack-ruby-bot/commands/support/help.rb, line 65
def command_name_and_desc(help_attrs)
  desc = help_attrs.command_desc.present? ? " - #{help_attrs.command_desc}" : ''
  "*#{help_attrs.command_name}*#{desc}"
end
help_attrs_with_present_names(help_attrs) click to toggle source
# File lib/slack-ruby-bot/commands/support/help.rb, line 70
def help_attrs_with_present_names(help_attrs)
  help_attrs.select { |k| k.command_name.present? }
end
other_commands_help_attrs() click to toggle source
# File lib/slack-ruby-bot/commands/support/help.rb, line 78
def other_commands_help_attrs
  commands_help_attrs.select { |k| k.klass.ancestors.include?(SlackRubyBot::Commands::Base) && !k.klass.ancestors.include?(SlackRubyBot::Bot) }
end