Sha256: a92afb51002b3328863d1529fe42248879c9d5458ef9d6277dceaea7ec84e6e5

Contents?: true

Size: 651 Bytes

Versions: 15

Compression:

Stored size: 651 Bytes

Contents

module Ruboty
  module Actions
    class Help < Base
      def call
        message.reply(body, code: true)
      end

      private

      def body
        action_descriptions.join("\n")
      end

      def action_descriptions
        Ruboty.actions.reject(&:hidden?).sort.map do |action|
          prefix = ""
          prefix << message.robot.name << " " unless  action.all?
          "%-#{pattern_max_length + prefix.size}s - #{action.description}" % "#{prefix}#{action.pattern.inspect}"
        end
      end

      def pattern_max_length
        Ruboty.actions.map {|action| action.pattern.inspect }.map(&:size).max
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
ruboty-1.1.9 lib/ruboty/actions/help.rb
ruboty-1.1.8 lib/ruboty/actions/help.rb
ruboty-1.1.7 lib/ruboty/actions/help.rb
ruboty-1.1.6 lib/ruboty/actions/help.rb
ruboty-1.1.5 lib/ruboty/actions/help.rb
ruboty-1.1.4 lib/ruboty/actions/help.rb
ruboty-1.1.3 lib/ruboty/actions/help.rb
ruboty-1.1.2 lib/ruboty/actions/help.rb
ruboty-1.1.1 lib/ruboty/actions/help.rb
ruboty-1.1.0 lib/ruboty/actions/help.rb
ruboty-1.0.4 lib/ruboty/actions/help.rb
ruboty-1.0.3 lib/ruboty/actions/help.rb
ruboty-1.0.2 lib/ruboty/actions/help.rb
ruboty-1.0.1 lib/ruboty/actions/help.rb
ruboty-1.0.0 lib/ruboty/actions/help.rb