Sha256: 5f0a92cf85ca2c07be4931c8f70745e1308447321f324b03e0cd42b91af76bff

Contents?: true

Size: 1.55 KB

Versions: 7

Compression:

Stored size: 1.55 KB

Contents

module Marvin
  class CoreCommands < CommandHandler
    
    # Returns a hash of doccumented method names
    def self.method_documentation
      documented = Hash.new { |h,k| h[k] = [] }
      @@method_descriptions.each_key do |klass| 
        next unless klass.registered?
        @@exposed_method_mapping[klass].each do |m|
          desc = @@method_descriptions[klass][m]
          documented[m.to_s] << desc if desc.present?
        end
      end
      return documented
    end
    
    def registered_and_exposed_handlers
    end
    
    exposes :help
    desc "Generates this usage statement"
    def help(method)
      method        = method.strip
      documentation = self.class.method_documentation
      names         = documentation.keys.sort
      if method.blank?
        display_names = names.map { |n| exposed_name(n) }
        width         = display_names.map { |d| d.length }.max
        say "Hello there, I know the following documented commands:"
        names.each_with_index do |name, index|
          say "#{display_names[index].ljust(width)} - #{documentation[name].join("; ")}"
        end
      else
        if names.include? method
          reply "#{exposed_name(method)} - #{documentation[method].join("; ")}"
        else
          reply "I'm sorry, I can't help with #{m} - it seems to be undocumented."
        end
      end
    end
    
    exposes :about
    desc "Displays the current marvin and ruby versions."
    def about(*args)
      reply "Marvin v#{Marvin::VERSION} running on Ruby #{RUBY_VERSION} (#{RUBY_PLATFORM})"
    end
    
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
Sutto-marvin-0.8.0.0 lib/marvin/core_commands.rb
Sutto-marvin-0.8.0.1 lib/marvin/core_commands.rb
marvin-0.8.2 lib/marvin/core_commands.rb
marvin-0.8.1 lib/marvin/core_commands.rb
marvin-0.8.0.2 lib/marvin/core_commands.rb
marvin-0.8.0.1 lib/marvin/core_commands.rb
marvin-0.8.0.0 lib/marvin/core_commands.rb