Module: UserInput

Included in:
Runner
Defined in:
lib/uss-enterprise/interactions.rb

Instance Method Summary collapse

Instance Method Details

#classesObject



54
55
56
57
58
# File 'lib/uss-enterprise/interactions.rb', line 54

def classes
  @classes = {

  }
end

#define_class_to_groupObject



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_flagsObject



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_groupsObject



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_classObject



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_flagObject



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


82
83
84
85
# File 'lib/uss-enterprise/interactions.rb', line 82

def print_options(options)
  # handle arrays and hashes as input
  # call .each_with_index and output the options
end

#promptObject



3
4
5
6
7
# File 'lib/uss-enterprise/interactions.rb', line 3

def prompt
  print "> "
  response = $stdin.gets.chomp
  return response
end