Class: CLI::BoardSelection
- Defined in:
- lib/ttt/interfaces/cli/lib/cli/board_selection.rb
Instance Attribute Summary collapse
-
#board ⇒ Object
Returns the value of attribute board.
-
#boards ⇒ Object
Returns the value of attribute boards.
-
#presenter ⇒ Object
Returns the value of attribute presenter.
Attributes inherited from Selection
Instance Method Summary collapse
- #board_selection_input_valid?(selection) ⇒ Boolean
-
#initialize(boards, presenter) ⇒ BoardSelection
constructor
A new instance of BoardSelection.
- #process ⇒ Object
- #process_board_selection(selection) ⇒ Object
- #set_board_string(selection) ⇒ Object
Methods inherited from Selection
Constructor Details
#initialize(boards, presenter) ⇒ BoardSelection
Returns a new instance of BoardSelection.
5 6 7 8 |
# File 'lib/ttt/interfaces/cli/lib/cli/board_selection.rb', line 5 def initialize(boards, presenter) self.boards = boards self.presenter = presenter end |
Instance Attribute Details
#board ⇒ Object
Returns the value of attribute board.
3 4 5 |
# File 'lib/ttt/interfaces/cli/lib/cli/board_selection.rb', line 3 def board @board end |
#boards ⇒ Object
Returns the value of attribute boards.
3 4 5 |
# File 'lib/ttt/interfaces/cli/lib/cli/board_selection.rb', line 3 def boards @boards end |
#presenter ⇒ Object
Returns the value of attribute presenter.
3 4 5 |
# File 'lib/ttt/interfaces/cli/lib/cli/board_selection.rb', line 3 def presenter @presenter end |
Instance Method Details
#board_selection_input_valid?(selection) ⇒ Boolean
25 26 27 28 |
# File 'lib/ttt/interfaces/cli/lib/cli/board_selection.rb', line 25 def board_selection_input_valid?(selection) return false if selection.class == Float 0 < selection && selection <= boards.length end |
#process ⇒ Object
10 11 12 13 14 |
# File 'lib/ttt/interfaces/cli/lib/cli/board_selection.rb', line 10 def process presenter.board_selection_prompt(boards) process_board_selection(presenter.input.chomp.to_i) self end |
#process_board_selection(selection) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/ttt/interfaces/cli/lib/cli/board_selection.rb', line 16 def process_board_selection(selection) if board_selection_input_valid?(selection) set_board_string(selection) else presenter.error process end end |
#set_board_string(selection) ⇒ Object
30 31 32 |
# File 'lib/ttt/interfaces/cli/lib/cli/board_selection.rb', line 30 def set_board_string(selection) self.board = boards[selection - 1] end |