Sha256: 98e5e884665a8e6b6b83a7e4b3cd5fae3a1856baf2d76d681fda7a6846f2d01f

Contents?: true

Size: 613 Bytes

Versions: 3

Compression:

Stored size: 613 Bytes

Contents

module Ellen
  module Actions
    class Help < Base
      def call
        message.reply(body)
      end

      private

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

      def action_descriptions
        Ellen.actions.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
        Ellen.actions.map {|action| action.pattern.inspect }.map(&:size).max
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ellen-0.2.2 lib/ellen/actions/help.rb
ellen-0.2.1 lib/ellen/actions/help.rb
ellen-0.2.0 lib/ellen/actions/help.rb