fantasy-football 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/fantasy_football/CLI.rb +19 -23
- data/lib/fantasy_football/player.rb +1 -1
- data/lib/fantasy_football/scraper.rb +14 -10
- data/lib/fantasy_football/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a4684cfcaed208aa4b48bb90c51a8aa6e7584de367ba55dea2811fb04146db62
|
4
|
+
data.tar.gz: 75ee2021047cef994803c356b80a6c0ae1ca55cd44692611348a3cfd8d82b3a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5ee4562b6b71d9aea5d5345bb48a3be5ddf59222757a81e94c7cdb176c05adec1cde8b052ccef09537bf90b792129940174a6bc2cef528cebfd3b3d9e7c25ff
|
7
|
+
data.tar.gz: c2bcf01de92742473279e12c587a26ad190dce1e5bfd1d6e708a9ff4bb7d767ca0dafc91d7013bb333c5022ac4a9311cba9571e7c72d6bc1d8e753b83f308d11
|
data/lib/fantasy_football/CLI.rb
CHANGED
@@ -2,23 +2,19 @@ class FantasyFootball::CLI
|
|
2
2
|
|
3
3
|
POSITIONS = ["qb", "rb", "te", "wr", "k"]
|
4
4
|
|
5
|
-
attr_accessor :position, :size # Stores current state of position choice
|
6
|
-
|
7
5
|
def welcome
|
8
6
|
puts " "
|
9
|
-
puts "Welcome to
|
7
|
+
puts "Welcome to NFL Fantasy Football Rankings and Players!"
|
10
8
|
puts " "
|
11
9
|
end
|
12
10
|
|
13
|
-
def choose_list_size
|
14
|
-
puts "How many player rankings would you like see
|
15
|
-
puts "Please enter a number between 1 and
|
16
|
-
|
17
|
-
if size.between?(1,
|
18
|
-
return
|
19
|
-
else
|
11
|
+
def choose_list_size(position)
|
12
|
+
puts "How many player rankings would you like see?"
|
13
|
+
puts "Please enter a number between 1 and #{FantasyFootball::Player.find_by_position(position).size}:"
|
14
|
+
@size = gets.strip.to_i
|
15
|
+
if !@size.between?(1,FantasyFootball::Player.find_by_position(position).size)
|
20
16
|
puts "Invalid entry - please enter a valid input:"
|
21
|
-
choose_list_size
|
17
|
+
choose_list_size(@position)
|
22
18
|
end
|
23
19
|
end
|
24
20
|
|
@@ -26,10 +22,11 @@ class FantasyFootball::CLI
|
|
26
22
|
# Asks for position and lists top players ranked by Fantasypros
|
27
23
|
puts "What position would you like to see rankings for?"
|
28
24
|
puts "Please enter QB, RB, TE, WR, or K:"
|
29
|
-
|
30
|
-
if POSITIONS.include?(position)
|
31
|
-
FantasyFootball::Scraper.scrape_rankings(position
|
32
|
-
|
25
|
+
@position = gets.strip.downcase
|
26
|
+
if POSITIONS.include?(@position)
|
27
|
+
FantasyFootball::Scraper.scrape_rankings(@position) if FantasyFootball::Player.find_by_position(@position) == []
|
28
|
+
choose_list_size(@position)
|
29
|
+
print_rankings(@size)
|
33
30
|
choose_player
|
34
31
|
else
|
35
32
|
puts "Invalid entry - please enter a valid input:"
|
@@ -37,11 +34,11 @@ class FantasyFootball::CLI
|
|
37
34
|
end
|
38
35
|
end
|
39
36
|
|
40
|
-
def print_rankings
|
41
|
-
# Iterates through Player
|
37
|
+
def print_rankings(size)
|
38
|
+
# Iterates through Player instances to print player name and rankings by position
|
42
39
|
puts " "
|
43
|
-
FantasyFootball::Player.find_by_position(position)
|
44
|
-
puts "-- Top #{size} #{position.upcase}s for Week #{p.week} of #{Time.new.year} --" if i == 0
|
40
|
+
FantasyFootball::Player.find_by_position(@position)[0..@size - 1].each_with_index {| p, i|
|
41
|
+
puts "-- Top #{size} #{@position.upcase}s for Week #{p.week} of #{Time.new.year} --" if i == 0
|
45
42
|
puts "#{p.rank}. #{p.name}"}
|
46
43
|
puts " "
|
47
44
|
end
|
@@ -50,7 +47,7 @@ class FantasyFootball::CLI
|
|
50
47
|
# Prompts for player rank #, outputs player details
|
51
48
|
puts "If you would like to see details about a player, enter their rank number. If not, enter N:"
|
52
49
|
rank = gets.strip
|
53
|
-
if rank.to_i.between?(1
|
50
|
+
if rank.to_i.between?(1,@size)
|
54
51
|
print_player(rank)
|
55
52
|
elsif rank.downcase == "n"
|
56
53
|
return
|
@@ -63,7 +60,7 @@ class FantasyFootball::CLI
|
|
63
60
|
def print_player(rank)
|
64
61
|
# Prints specific player using a custom class finder
|
65
62
|
blank = " "
|
66
|
-
p = FantasyFootball::Player.find_by_rank_and_position(rank, position)
|
63
|
+
p = FantasyFootball::Player.find_by_rank_and_position(rank, @position)
|
67
64
|
FantasyFootball::Scraper.add_attr(p)
|
68
65
|
puts blank
|
69
66
|
puts " Player Stats "
|
@@ -86,7 +83,7 @@ class FantasyFootball::CLI
|
|
86
83
|
puts "Please enter 1, 2, or quit."
|
87
84
|
input = gets.strip.downcase
|
88
85
|
if input == "1"
|
89
|
-
print_rankings
|
86
|
+
print_rankings(@size)
|
90
87
|
choose_player
|
91
88
|
elsif input == "2"
|
92
89
|
choose_position
|
@@ -101,7 +98,6 @@ class FantasyFootball::CLI
|
|
101
98
|
|
102
99
|
def run
|
103
100
|
welcome
|
104
|
-
choose_list_size
|
105
101
|
choose_position
|
106
102
|
again?
|
107
103
|
end
|
@@ -17,7 +17,7 @@ class FantasyFootball::Player
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def self.find_by_position(position)
|
20
|
-
all.select {|i| i.position == position.upcase}
|
20
|
+
all.select {|i| i.position == position.upcase}.sort {|a,b| a.rank.to_i <=> b.rank.to_i}
|
21
21
|
end
|
22
22
|
|
23
23
|
def self.find_by_rank_and_position(rank, position)
|
@@ -1,22 +1,26 @@
|
|
1
1
|
class FantasyFootball::Scraper
|
2
2
|
|
3
|
-
def self.scrape_rankings(position
|
3
|
+
def self.scrape_rankings(position)
|
4
4
|
doc = Nokogiri::HTML(open("https://www.fantasypros.com/nfl/rankings/#{position}.php"))
|
5
5
|
week = doc.css('h1').text.split[5]
|
6
6
|
table = doc.css('tbody tr') # Selects the HTML table with player rankings
|
7
|
-
build_players(table, position, week
|
7
|
+
build_players(table, position, week)
|
8
8
|
end
|
9
9
|
|
10
|
-
def self.build_players(table, position, week
|
10
|
+
def self.build_players(table, position, week)
|
11
11
|
# Input is HTML table of player rankings, instantiates Players, assigns name, rank, and url
|
12
|
+
|
12
13
|
table.each_with_index do |t, i|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
14
|
+
begin
|
15
|
+
if t.css('td')[0].text.to_i > 0
|
16
|
+
p = FantasyFootball::Player.new
|
17
|
+
p.name = t.css('span.full-name').text
|
18
|
+
p.rank = t.css('td')[0].text
|
19
|
+
p.url = "https://www.fantasypros.com" + t.css('a')[0]["href"]
|
20
|
+
p.week = week
|
21
|
+
p.position = position.upcase
|
22
|
+
end
|
23
|
+
rescue NoMethodError
|
20
24
|
end
|
21
25
|
end
|
22
26
|
end
|