Class: CLI

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

Constant Summary collapse

OFFSET =
1

Instance Method Summary collapse

Constructor Details

#initialize(input = $stdin, output = $stdout) ⇒ CLI

Returns a new instance of CLI.



12
13
14
15
16
# File 'lib/cli.rb', line 12

def initialize(input=$stdin, output=$stdout)
  @input = input
  @output = output
  run_app
end

Instance Method Details

#choose_player_type(options) ⇒ Object



22
23
24
# File 'lib/cli.rb', line 22

def choose_player_type(options)
  get_valid_input(options)
end

#get_valid_input(options) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/cli.rb', line 31

def get_valid_input(options)
  choice = @input.gets.chomp.to_i
  if options.include? choice
    choice
  else
    @output.puts "Invalid Selection"
    get_valid_input(options)
  end
end

#place_marker(options) ⇒ Object



26
27
28
29
# File 'lib/cli.rb', line 26

def place_marker(options)
  offset_spaces = options.map {|space| space + OFFSET}
  get_valid_input(offset_spaces) - OFFSET
end

#select_board_size(options) ⇒ Object



18
19
20
# File 'lib/cli.rb', line 18

def select_board_size(options)
  get_valid_input(options)
end