class FantasyFootball::CLI

Constants

POSITIONS

Public Instance Methods

again?() click to toggle source
# File lib/fantasy_football/CLI.rb, line 80
def again?
  # Allows user to see details about a different player on the current rank list, choose a different rank list, or quit
  puts "Would you like to: 1. see details about a different player, 2. see rankings for a different position, or quit?"
  puts "Please enter 1, 2, or quit."
  input = gets.strip.downcase
  if input == "1"
    print_rankings(@size)
    choose_player
  elsif input == "2"
    choose_position
  elsif input == "quit"
    exit
  else
    puts "Invalid entry - please enter a valid input:"
    again?
  end
  again?
end
choose_list_size(position) click to toggle source
# File lib/fantasy_football/CLI.rb, line 11
def choose_list_size(position)
  puts "How many player rankings would you like see?"
  puts "Please enter a number between 1 and #{FantasyFootball::Player.find_by_position(position).size}:"
  @size = gets.strip.to_i
  if !@size.between?(1,FantasyFootball::Player.find_by_position(position).size)
    puts "Invalid entry - please enter a valid input:"
    choose_list_size(@position)
  end
end
choose_player() click to toggle source
# File lib/fantasy_football/CLI.rb, line 46
def choose_player
  # Prompts for player rank #, outputs player details
  puts "If you would like to see details about a player, enter their rank number. If not, enter N:"
  rank = gets.strip
  if rank.to_i.between?(1,@size)
    print_player(rank)
  elsif rank.downcase == "n"
    return
  else
    puts "Invalid entry - please enter a valid input:"
    choose_player
  end
end
choose_position() click to toggle source
# File lib/fantasy_football/CLI.rb, line 21
def choose_position
  # Asks for position and lists top players ranked by Fantasypros
  puts "What position would you like to see rankings for?"
  puts "Please enter QB, RB, TE, WR, or K:"
  @position = gets.strip.downcase
  if POSITIONS.include?(@position)
    FantasyFootball::Scraper.scrape_rankings(@position) if FantasyFootball::Player.find_by_position(@position) == []
    choose_list_size(@position)
    print_rankings(@size)
    choose_player
  else
    puts "Invalid entry - please enter a valid input:"
    choose_position
  end
end
print_player(rank) click to toggle source
print_rankings(size) click to toggle source
run() click to toggle source
# File lib/fantasy_football/CLI.rb, line 99
def run
  welcome
  choose_position
  again?
end
welcome() click to toggle source
# File lib/fantasy_football/CLI.rb, line 5
def welcome
  puts " "
  puts "Welcome to NFL Fantasy Football Rankings and Players!"
  puts " "
end