Class: SRSGame::Commands

Inherits:
Object show all
Defined in:
lib/srs_game.rb

Overview

class Settings

Class Method Summary (collapse)

Class Method Details

+ (Object) _exit(r) Also known as: _quit

Quit the game



360
361
362
# File 'lib/srs_game.rb', line 360

def _exit(r)
  exit
end

+ (Object) _help(r) Also known as: _?

Display help text



365
366
367
368
369
# File 'lib/srs_game.rb', line 365

def _help(r)
  puts "For help on a specific command, use `man [command]'".red.strikethrough + " " + "COMING SOON".underline
  puts "For a list of all commands, use `help --all'"
  puts "All available commands:\n#{callable_methods.map(&:command_pp).to_sentence(:bold => true)}" if r =~ /--all/
end

+ (Object) callable_methods

def method_missing



313
314
315
# File 'lib/srs_game.rb', line 313

def callable_methods
  methods.grep(/^_\w+[^_]$/)
end

+ (Object) matching_methods(s = '', m = callable_methods)



318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
# File 'lib/srs_game.rb', line 318

def matching_methods(s='', m=callable_methods)
  # build a regex which starts with ^ (beginning)
  # take every letter of the method_name
  #   insert "(.*?)" instead, which means: match anything and take the smallest match
  #   and insert the letter itself (but escape regex chars)
  #
  # for example s='matz'
  # => /^(.*?)m(.*?)a(.*?)t(.*?)z/
  #
  r=/^#{s.to_s.gsub(/./){"(.*?)"+Regexp.escape($&)}}/

  # match all available methods for this regex
  #  and sort them by the least matches of the "fill" regex groups
  m.grep(r).sort_by do |i|
    i.to_s.match(r).captures.map(&:size) << i
  end # sort_by
end

+ (Object) method_missing(m, a)



309
310
311
# File 'lib/srs_game.rb', line 309

def method_missing(m, a)
  puts "#{self}::#{m.downcase}: not found".red
end

+ (Object) parse(input)

def matching_methods



336
337
338
339
340
# File 'lib/srs_game.rb', line 336

def parse(input)
  method = input.words.first
  argument_string = input.remove_first_word
  __send__("_" + method.command_pp, argument_string)
end