Class: CLI::PlayAgain

Inherits:
Object
  • Object
show all
Defined in:
lib/ttt/interfaces/cli/lib/cli/play_again.rb

Instance Method Summary collapse

Constructor Details

#initialize(presenter) ⇒ PlayAgain

Returns a new instance of PlayAgain.



4
5
6
# File 'lib/ttt/interfaces/cli/lib/cli/play_again.rb', line 4

def initialize(presenter)
  self.presenter = presenter
end

Instance Method Details

#inputObject



23
24
25
# File 'lib/ttt/interfaces/cli/lib/cli/play_again.rb', line 23

def input
  presenter.input
end

#play_again?Boolean

Returns:

  • (Boolean)


8
9
10
11
# File 'lib/ttt/interfaces/cli/lib/cli/play_again.rb', line 8

def play_again?
  play_again_msg
  process_reply input
end

#play_again_msgObject



31
32
33
# File 'lib/ttt/interfaces/cli/lib/cli/play_again.rb', line 31

def play_again_msg
  presenter.play_again_msg
end

#process_reply(reply) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/ttt/interfaces/cli/lib/cli/play_again.rb', line 13

def process_reply reply
  if valid_reply?(reply)
    return false if reply.chomp == "n"
    true
  else
    presenter.error
    play_again?
  end
end

#valid_reply?(response) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/ttt/interfaces/cli/lib/cli/play_again.rb', line 27

def valid_reply?(response)
  response =~ (/(y|n)/i)
end