commands.rb 504 B

12345678910111213141516171819202122232425262728
  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. def description
  11. @description
  12. end
  13. def options
  14. @options
  15. end
  16. def call(message_str, event=nil)
  17. match = /pkmn-\w+\s?(.*)/.match(message_str)
  18. args = match[1]
  19. params = args.split(/\s?\|\s?/).reject(&:empty?)
  20. operation.call(event, *params)
  21. end
  22. end