Class: BucsRoster::CLI

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

Instance Method Summary collapse

Instance Method Details

#ask_againObject



39
40
41
42
43
44
45
46
47
# File 'lib/bucs_roster/cli.rb', line 39

def ask_again
  puts "Would you like to explore another player? (Y/N)"
  input = gets.strip.downcase
  if input[0] == "y"
    menu
  else
    goodbye
  end
end

#goodbyeObject



49
50
51
52
# File 'lib/bucs_roster/cli.rb', line 49

def goodbye
  puts "Thanks for checking out the Tampa Bay Bucs!"
  exit
end


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/bucs_roster/cli.rb', line 8

def menu
  @pointer ||= 0
  Player.all[@pointer,30].each.with_index(@pointer+1) do |player, index|
    puts "#{index}. #{player.name}"
  end
    puts "Enter the number of the player you would like to know more about, '+' for next group, '-' for previous group or type 'exit' to end."
    user_input = gets.strip
  case user_input
    when "exit"
      goodbye
    when "+"
      @pointer += 30
      @pointer = (Player.all.count)-30 if @pointer > Player.all.count
      menu
    when "-"
      @pointer -= 30
      @pointer = 0 if @pointer < 0
      menu
    end
  user_input = user_input.to_i
  if user_input.between?(1, Player.all.count)
      user_input -=1
      Scraper.scrape_player(user_input)
      Player.show_player_info(user_input)
      ask_again
  else
      puts "Invalid entry.  Please try again."
      menu
    end
end

#startObject



2
3
4
5
6
# File 'lib/bucs_roster/cli.rb', line 2

def start
  puts "Here are your Tampa Bay Buccaneers!"
  Scraper.new.scrape_index
  menu
end