Class: CLI::PlayerSelection
- Defined in:
- lib/ttt/interfaces/cli/lib/cli/player_selection.rb
Instance Attribute Summary collapse
-
#player1 ⇒ Object
Returns the value of attribute player1.
-
#player2 ⇒ Object
Returns the value of attribute player2.
-
#players ⇒ Object
Returns the value of attribute players.
-
#presenter ⇒ Object
Returns the value of attribute presenter.
Attributes inherited from Selection
Instance Method Summary collapse
- #_player(selection) ⇒ Object
-
#initialize(players, presenter) ⇒ PlayerSelection
constructor
A new instance of PlayerSelection.
- #player_selection_valid?(selection) ⇒ Boolean
- #process ⇒ Object
- #process_player_type_input(num, selection) ⇒ Object
- #set_player_string(num, selection) ⇒ Object
Methods inherited from Selection
Constructor Details
#initialize(players, presenter) ⇒ PlayerSelection
Returns a new instance of PlayerSelection.
6 7 8 9 |
# File 'lib/ttt/interfaces/cli/lib/cli/player_selection.rb', line 6 def initialize(players, presenter) self.presenter = presenter self.players = players end |
Instance Attribute Details
#player1 ⇒ Object
Returns the value of attribute player1.
5 6 7 |
# File 'lib/ttt/interfaces/cli/lib/cli/player_selection.rb', line 5 def player1 @player1 end |
#player2 ⇒ Object
Returns the value of attribute player2.
5 6 7 |
# File 'lib/ttt/interfaces/cli/lib/cli/player_selection.rb', line 5 def player2 @player2 end |
#players ⇒ Object
Returns the value of attribute players.
5 6 7 |
# File 'lib/ttt/interfaces/cli/lib/cli/player_selection.rb', line 5 def players @players end |
#presenter ⇒ Object
Returns the value of attribute presenter.
5 6 7 |
# File 'lib/ttt/interfaces/cli/lib/cli/player_selection.rb', line 5 def presenter @presenter end |
Instance Method Details
#_player(selection) ⇒ Object
35 36 37 |
# File 'lib/ttt/interfaces/cli/lib/cli/player_selection.rb', line 35 def _player(selection) players[selection - 1] end |
#player_selection_valid?(selection) ⇒ Boolean
39 40 41 |
# File 'lib/ttt/interfaces/cli/lib/cli/player_selection.rb', line 39 def player_selection_valid?(selection) 0 < selection.to_i && selection <= players.length end |
#process ⇒ Object
11 12 13 14 15 |
# File 'lib/ttt/interfaces/cli/lib/cli/player_selection.rb', line 11 def process process_player_type_input(1, presenter.player_type_prompt(1, players)) process_player_type_input(2, presenter.player_type_prompt(2, players)) self end |
#process_player_type_input(num, selection) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/ttt/interfaces/cli/lib/cli/player_selection.rb', line 17 def process_player_type_input(num, selection) if player_selection_valid? selection.chomp.to_i set_player_string(num, selection.chomp.to_i) else presenter.error process_player_type_input(num, presenter.player_type_prompt(num, players)) end end |
#set_player_string(num, selection) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/ttt/interfaces/cli/lib/cli/player_selection.rb', line 26 def set_player_string(num, selection) case num when 1 self.player1 = _player(selection) when 2 self.player2 = _player(selection) end end |