Class: FantasyFootball::CLI

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

Constant Summary collapse

POSITIONS =
["qb", "rb", "te", "wr", "k"]

Instance Method Summary collapse

Instance Method Details

#again?Boolean

Returns:

  • (Boolean)


80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# 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) ⇒ Object



11
12
13
14
15
16
17
18
19
# 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_playerObject



46
47
48
49
50
51
52
53
54
55
56
57
58
# 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_positionObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# 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


60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/fantasy_football/CLI.rb', line 60

def print_player(rank)
  # Prints specific player using a custom class finder
  blank = " "
  p = FantasyFootball::Player.find_by_rank_and_position(rank, @position)
  FantasyFootball::Scraper.add_attr(p)
  puts blank
  puts "         Player Stats              "
  puts "-------------------------------    "
  puts "Name: #{p.name}                    "
  puts "Position: #{p.position}            "
  puts "Projection: #{p.projection} points "
  puts "Team: #{p.team}                    "
  puts "Height: #{p.height}                "
  puts "Weight: #{p.weight} lbs.           "
  puts "Age: #{p.age}                      "
  puts "College: #{p.college}              "
  puts "-------------------------------    "
  puts blank
end


37
38
39
40
41
42
43
44
# File 'lib/fantasy_football/CLI.rb', line 37

def print_rankings(size)
  # Iterates through Player instances to print player name and rankings by position
  puts " "
  FantasyFootball::Player.find_by_position(@position)[0..@size - 1].each_with_index {| p, i|
    puts "-- Top #{size} #{@position.upcase}s for Week #{p.week} of #{Time.new.year} --" if i == 0
    puts "#{p.rank}. #{p.name}"}
  puts " "
end

#runObject



99
100
101
102
103
# File 'lib/fantasy_football/CLI.rb', line 99

def run
  welcome
  choose_position
  again?
end

#welcomeObject



5
6
7
8
9
# File 'lib/fantasy_football/CLI.rb', line 5

def welcome
  puts " "
  puts "Welcome to NFL Fantasy Football Rankings and Players!"
  puts " "
end