commands.rb 481 B

123456789101112131415161718192021222324
  1. require 'optparse'
  2. class Command
  3. attr_reader :name, :operation
  4. def initialize(name, description, options = {}, &block)
  5. @name = name
  6. @description = description
  7. @options = options
  8. @operation = block
  9. end
  10. attr_reader :description
  11. attr_reader :options
  12. def call(message_str, event=nil)
  13. match = /pkmn-\w+\s?(.*)/.match(message_str)
  14. args = match[1]
  15. params = args.split(/\s?\|\s?/).reject(&:empty?)
  16. operation.call(event, *params)
  17. end
  18. end