Class: Marvin::CoreCommands
- Inherits:
-
CommandHandler
- Object
- Base
- CommandHandler
- Marvin::CoreCommands
- Defined in:
- lib/marvin/core_commands.rb
Instance Attribute Summary
Attributes inherited from Base
#client, #from, #options, #target
Class Method Summary collapse
-
.method_documentation ⇒ Object
Returns a hash of doccumented method names.
Instance Method Summary collapse
Methods inherited from CommandHandler
#check_for_commands, command, desc, exposed_methods, #exposed_name, exposed_name, exposes, #extract_command_name, method_added, prefix_is, prefix_regexp, reloading!
Methods inherited from Base
#_handle, #action, #addressed?, #ctcp, event_handlers_for, #from_channel?, #from_user?, #handle, #handle_incoming_numeric, #msg, on_event, on_numeric, #pm, register!, #registered=, registered=, registered?, reloaded!, reloading!, #reply
Class Method Details
.method_documentation ⇒ Object
Returns a hash of doccumented method names
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/marvin/core_commands.rb', line 5 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 |
Instance Method Details
#about(*args) ⇒ Object
44 45 46 |
# File 'lib/marvin/core_commands.rb', line 44 def about(*args) reply "Marvin v#{Marvin::VERSION} running on Ruby #{RUBY_VERSION} (#{RUBY_PLATFORM})" end |
#help(method) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/marvin/core_commands.rb', line 22 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 |
#registered_and_exposed_handlers ⇒ Object
17 18 |
# File 'lib/marvin/core_commands.rb', line 17 def registered_and_exposed_handlers end |