Module: UserInput
- Included in:
- Runner
- Defined in:
- lib/uss-enterprise/interactions.rb
Instance Method Summary collapse
- #classes ⇒ Object
- #define_class_to_group ⇒ Object
- #define_cli_flags ⇒ Object
- #define_groups ⇒ Object
- #define_letter_to_class ⇒ Object
- #l_flag ⇒ Object
- #look_up_class_group(s_class) ⇒ Object
- #look_up_letter_class(letter) ⇒ Object
- #print_options(options) ⇒ Object
- #prompt ⇒ Object
Instance Method Details
#classes ⇒ Object
54 55 56 57 58 |
# File 'lib/uss-enterprise/interactions.rb', line 54 def classes @classes = { } end |
#define_class_to_group ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/uss-enterprise/interactions.rb', line 22 def define_class_to_group @class_to_group = { 'intrepid' => 'StarShip', 'sovereign' => 'StarShip', 'galaxy' => 'StarShip', 'ambassador' => 'StarShip', 'excelsior' => 'StarShip', 'constitution' => 'StarShip', 'constitution - refit' => 'StarShip', 'nx' => 'StarShip', 'spaceshuttle' => 'OrbitalShip', 'carrier' => 'SeaShip', 'sloop' => 'SeaShip' } @class_to_group end |
#define_cli_flags ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/uss-enterprise/interactions.rb', line 9 def define_cli_flags @flags = { '-c' => "ship class", '-g' => "ship group (starship, seaship, orbitalship)", '-C' => "captain", '-i' => "interactive", '-r' => "random", '-n' => "number (of ships)", '-l' => "letter" } @flags end |
#define_groups ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/uss-enterprise/interactions.rb', line 45 def define_groups @groups = { 'star' => 'StarShip', 'sea' => 'SeaShip', 'orbital' => 'OrbitalShip' } @groups end |
#define_letter_to_class ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/uss-enterprise/interactions.rb', line 60 def define_letter_to_class @letter_to_class = { 'rev' => 'Sloop', 'cvn' => 'Carrier', 'ov' => 'Spaceshuttle', 'nx' => 'NX', 'none' => 'Constitution', 'a' => 'Constitution - refit', 'b' => 'Excelsior', 'c' => 'Ambassador', 'd' => 'Galaxy', 'e' => 'Sovereign', 'voy' => 'Intrepid' } @letter_to_class end |
#l_flag ⇒ Object
87 88 89 90 91 92 93 |
# File 'lib/uss-enterprise/interactions.rb', line 87 def l_flag index_of_requested_letter = @params.find_index('-l') + 1 ship_letter = @params[index_of_requested_letter] ship_class = look_up_letter_class(ship_letter) ship_group = look_up_class_group(ship_class) self.build_ship(ship_group, ship_class) end |
#look_up_class_group(s_class) ⇒ Object
39 40 41 42 43 |
# File 'lib/uss-enterprise/interactions.rb', line 39 def look_up_class_group(s_class) s_class = s_class.downcase group = @class_to_group[s_class] return group end |
#look_up_letter_class(letter) ⇒ Object
77 78 79 80 |
# File 'lib/uss-enterprise/interactions.rb', line 77 def look_up_letter_class(letter) s_class = @letter_to_class[letter] return s_class end |
#print_options(options) ⇒ Object
82 83 84 85 |
# File 'lib/uss-enterprise/interactions.rb', line 82 def () # handle arrays and hashes as input # call .each_with_index and output the options end |
#prompt ⇒ Object
3 4 5 6 7 |
# File 'lib/uss-enterprise/interactions.rb', line 3 def prompt print "> " response = $stdin.gets.chomp return response end |