Class: CLI::BoardSelection

Inherits:
Selection show all
Defined in:
lib/ttt/interfaces/cli/lib/cli/board_selection.rb

Instance Attribute Summary collapse

Attributes inherited from Selection

#players

Instance Method Summary collapse

Methods inherited from Selection

#input

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

#boardObject

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

#boardsObject

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

#presenterObject

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

Returns:

  • (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

#processObject



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