Class: CLI::WalkHistory
- Inherits:
-
Object
- Object
- CLI::WalkHistory
- Defined in:
- lib/ttt/interfaces/cli/lib/cli/walk_history.rb
Instance Attribute Summary collapse
-
#board ⇒ Object
Returns the value of attribute board.
-
#game ⇒ Object
Returns the value of attribute game.
-
#move_traverser ⇒ Object
Returns the value of attribute move_traverser.
-
#presenter ⇒ Object
Returns the value of attribute presenter.
Instance Method Summary collapse
- #build_board(board = game.board, move_index = move_traverser.move_index) ⇒ Object
-
#initialize(presenter, game) ⇒ WalkHistory
constructor
A new instance of WalkHistory.
- #post_game_msg ⇒ Object
- #process(selection) ⇒ Object
- #walk_history(diff_index) ⇒ Object
- #walk_msg ⇒ Object
Constructor Details
#initialize(presenter, game) ⇒ WalkHistory
Returns a new instance of WalkHistory.
4 5 6 7 8 |
# File 'lib/ttt/interfaces/cli/lib/cli/walk_history.rb', line 4 def initialize(presenter, game) self.presenter = presenter self.move_traverser = game.history.move_traverser self.game = game end |
Instance Attribute Details
#board ⇒ Object
Returns the value of attribute board.
3 4 5 |
# File 'lib/ttt/interfaces/cli/lib/cli/walk_history.rb', line 3 def board @board end |
#game ⇒ Object
Returns the value of attribute game.
3 4 5 |
# File 'lib/ttt/interfaces/cli/lib/cli/walk_history.rb', line 3 def game @game end |
#move_traverser ⇒ Object
Returns the value of attribute move_traverser.
3 4 5 |
# File 'lib/ttt/interfaces/cli/lib/cli/walk_history.rb', line 3 def move_traverser @move_traverser end |
#presenter ⇒ Object
Returns the value of attribute presenter.
3 4 5 |
# File 'lib/ttt/interfaces/cli/lib/cli/walk_history.rb', line 3 def presenter @presenter end |
Instance Method Details
#build_board(board = game.board, move_index = move_traverser.move_index) ⇒ Object
44 45 46 |
# File 'lib/ttt/interfaces/cli/lib/cli/walk_history.rb', line 44 def build_board(board = game.board, move_index = move_traverser.move_index) move_traverser.history_board_builder(board, move_index) end |
#post_game_msg ⇒ Object
10 11 12 13 |
# File 'lib/ttt/interfaces/cli/lib/cli/walk_history.rb', line 10 def post_game_msg presenter.post_game_msg process(presenter.input.chomp) end |
#process(selection) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/ttt/interfaces/cli/lib/cli/walk_history.rb', line 15 def process(selection) if selection =~ (/y|n/i) walk_msg if selection =~ (/y/i) else presenter.error post_game_msg end end |
#walk_history(diff_index) ⇒ Object
39 40 41 42 |
# File 'lib/ttt/interfaces/cli/lib/cli/walk_history.rb', line 39 def walk_history(diff_index) move_traverser.adjust_move_index(diff_index) walk_msg end |
#walk_msg ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/ttt/interfaces/cli/lib/cli/walk_history.rb', line 24 def walk_msg presenter.clear presenter.output_board(build_board) presenter.walk_msg diff_index = presenter.input.chomp case diff_index when "-1" then walk_history(-1) when "0" then return when "1" then walk_history(1) else presenter.error walk_msg end end |