Method: Whatsa::CLI#gets_command

Defined in:
lib/whatsa/cli.rb

#gets_command(treat_as_query = false) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/whatsa/cli.rb', line 34

def gets_command(treat_as_query = false)
  command_type = {
    "exit" => "exit",
    "quit" => "exit",
    "q"    => "exit",

    "help"         => "help",
    "h"            => "help",
    "instructions": ("help" unless treat_as_query),

    "new"            => "new",
    "different"      => ("new" unless treat_as_query),
    "something else" => ("new" unless treat_as_query),
    "again"          => ("new" unless treat_as_query),

    "other"      => ("other" unless treat_as_query),
    "categories" => ("other" unless treat_as_query),
    "category"   => ("other" unless treat_as_query),
    "dig"        => ("other" unless treat_as_query),

    "" => "blank"
  }

  loop do
    print "> "
    input = gets.strip.downcase
    case command_type[input]
    when "exit"  then exit
    when "help"  then instructions
    when "new"   then return run
    when "other" then return "other"
    when ""      then next
    else return input
    end
  end
end