fantasy-football 0.1.9 → 0.2.0
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 +24 -9
- data/lib/fantasy_football/player.rb +12 -3
- data/lib/fantasy_football/scraper.rb +3 -8
- data/lib/fantasy_football/version.rb +1 -1
- metadata +2 -4
- data/lib/fantasy_football/concerns/findable.rb +0 -19
- data/lib/fantasy_football/concerns/memorable.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5bbf6659d9889db6ad0064054b7cac10c58876f5ca71762882d76fc189cd37f7
|
4
|
+
data.tar.gz: 98d2cba1d007c6e2698154bc910fc8647031cd8ce996fba8be3529a008332013
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 14ee8a4219df44ec57d426e49adbcaf5d0be1c37c76dd2c18a50193b923519d510abe35be1e3fd3e960b29deb0607c6b0ecd367c5c68607d20f875e47d930275
|
7
|
+
data.tar.gz: 5a39dbd9ea69a765d80cd0324e44282e6153850d217df7c21b3c843ed4a02bdf689f2b3e9b43d8dc364f5b18db75a8c4e393b468c035cdf2f834e0a30598fa26
|
data/lib/fantasy_football/CLI.rb
CHANGED
@@ -2,24 +2,38 @@ class FantasyFootball::CLI
|
|
2
2
|
|
3
3
|
POSITIONS = ["qb", "rb", "te", "wr", "k"]
|
4
4
|
|
5
|
-
attr_accessor :position # Stores current state of position choice
|
5
|
+
attr_accessor :position, :size # Stores current state of position choice
|
6
6
|
|
7
7
|
def welcome
|
8
|
+
puts " "
|
8
9
|
puts "Welcome to the NFL Fantasy Football Rankings and Players!"
|
10
|
+
puts " "
|
11
|
+
end
|
12
|
+
|
13
|
+
def choose_list_size
|
14
|
+
puts "How many player rankings would you like see per position?"
|
15
|
+
puts "Please enter a number between 1 and 25:"
|
16
|
+
self.size = gets.strip.to_i
|
17
|
+
if size.between?(1,25)
|
18
|
+
return
|
19
|
+
else
|
20
|
+
puts "Invalid entry - please enter a valid input:"
|
21
|
+
choose_list_size
|
22
|
+
end
|
9
23
|
end
|
10
24
|
|
11
|
-
def
|
25
|
+
def choose_position
|
12
26
|
# Asks for position and lists top players ranked by Fantasypros
|
13
27
|
puts "What position would you like to see rankings for?"
|
14
28
|
puts "Please enter QB, RB, TE, WR, or K:"
|
15
29
|
self.position = gets.strip.downcase
|
16
30
|
if POSITIONS.include?(position)
|
17
|
-
FantasyFootball::Scraper.scrape_rankings(position) if FantasyFootball::Player.find_by_position(position) == []
|
31
|
+
FantasyFootball::Scraper.scrape_rankings(position, size) if FantasyFootball::Player.find_by_position(position) == []
|
18
32
|
print_rankings
|
19
33
|
choose_player
|
20
34
|
else
|
21
35
|
puts "Invalid entry - please enter a valid input:"
|
22
|
-
|
36
|
+
choose_position
|
23
37
|
end
|
24
38
|
end
|
25
39
|
|
@@ -27,7 +41,7 @@ class FantasyFootball::CLI
|
|
27
41
|
# Iterates through Player.all to print player name and rankings by position
|
28
42
|
puts " "
|
29
43
|
FantasyFootball::Player.find_by_position(position).sort {|a,b| a.rank.to_i <=> b.rank.to_i}.each_with_index {| p, i|
|
30
|
-
puts "-- Top #{
|
44
|
+
puts "-- Top #{size} #{position.upcase}s for Week #{p.week} of #{Time.new.year} --" if i == 0
|
31
45
|
puts "#{p.rank}. #{p.name}"}
|
32
46
|
puts " "
|
33
47
|
end
|
@@ -36,7 +50,7 @@ class FantasyFootball::CLI
|
|
36
50
|
# Prompts for player rank #, outputs player details
|
37
51
|
puts "If you would like to see details about a player, enter their rank number. If not, enter N:"
|
38
52
|
rank = gets.strip
|
39
|
-
if rank.to_i.between?(1,
|
53
|
+
if rank.to_i.between?(1,size)
|
40
54
|
print_player(rank)
|
41
55
|
elsif rank.downcase == "n"
|
42
56
|
return
|
@@ -48,7 +62,7 @@ class FantasyFootball::CLI
|
|
48
62
|
|
49
63
|
def print_player(rank)
|
50
64
|
# Prints specific player using a custom class finder
|
51
|
-
blank = "
|
65
|
+
blank = " "
|
52
66
|
p = FantasyFootball::Player.find_by_rank_and_position(rank, position)
|
53
67
|
FantasyFootball::Scraper.add_attr(p)
|
54
68
|
puts blank
|
@@ -75,7 +89,7 @@ class FantasyFootball::CLI
|
|
75
89
|
print_rankings
|
76
90
|
choose_player
|
77
91
|
elsif input == "2"
|
78
|
-
|
92
|
+
choose_position
|
79
93
|
elsif input == "quit"
|
80
94
|
exit
|
81
95
|
else
|
@@ -87,7 +101,8 @@ class FantasyFootball::CLI
|
|
87
101
|
|
88
102
|
def run
|
89
103
|
welcome
|
90
|
-
|
104
|
+
choose_list_size
|
105
|
+
choose_position
|
91
106
|
again?
|
92
107
|
end
|
93
108
|
|
@@ -1,8 +1,5 @@
|
|
1
1
|
class FantasyFootball::Player
|
2
2
|
|
3
|
-
extend Findable::ClassMethods
|
4
|
-
include Memorable::InstanceMethods
|
5
|
-
|
6
3
|
attr_accessor :name, :position, :projection, :team, :height, :weight, :age, :college, :rank, :url, :week
|
7
4
|
|
8
5
|
@@all = []
|
@@ -15,4 +12,16 @@ class FantasyFootball::Player
|
|
15
12
|
@@all
|
16
13
|
end
|
17
14
|
|
15
|
+
def save
|
16
|
+
@@all << self
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.find_by_position(position)
|
20
|
+
all.select {|i| i.position == position.upcase}
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.find_by_rank_and_position(rank, position)
|
24
|
+
all.find {|i| i.rank == rank && i.position == position.upcase}
|
25
|
+
end
|
26
|
+
|
18
27
|
end
|
@@ -1,18 +1,13 @@
|
|
1
1
|
class FantasyFootball::Scraper
|
2
2
|
|
3
|
-
def self.size
|
4
|
-
20
|
5
|
-
end
|
6
|
-
|
7
|
-
def self.scrape_rankings(position)
|
3
|
+
def self.scrape_rankings(position, size)
|
8
4
|
doc = Nokogiri::HTML(open("https://www.fantasypros.com/nfl/rankings/#{position}.php"))
|
9
|
-
# binding.pry
|
10
5
|
week = doc.css('h1').text.split[5]
|
11
6
|
table = doc.css('tbody tr') # Selects the HTML table with player rankings
|
12
|
-
build_players(table, position, week)
|
7
|
+
build_players(table, position, week, size)
|
13
8
|
end
|
14
9
|
|
15
|
-
def self.build_players(table, position, week)
|
10
|
+
def self.build_players(table, position, week, size)
|
16
11
|
# Input is HTML table of player rankings, instantiates Players, assigns name, rank, and url
|
17
12
|
table.each_with_index do |t, i|
|
18
13
|
if i < size
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fantasy-football
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "'Mike Dilley'"
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-11-
|
11
|
+
date: 2018-11-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -188,8 +188,6 @@ files:
|
|
188
188
|
- fantasy-football.gemspec
|
189
189
|
- lib/fantasy-football.rb
|
190
190
|
- lib/fantasy_football/CLI.rb
|
191
|
-
- lib/fantasy_football/concerns/findable.rb
|
192
|
-
- lib/fantasy_football/concerns/memorable.rb
|
193
191
|
- lib/fantasy_football/player.rb
|
194
192
|
- lib/fantasy_football/scraper.rb
|
195
193
|
- lib/fantasy_football/version.rb
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module Findable
|
2
|
-
|
3
|
-
module ClassMethods
|
4
|
-
|
5
|
-
def find_by_position(position)
|
6
|
-
self.all.select {|i| i.position == position.upcase}
|
7
|
-
end
|
8
|
-
|
9
|
-
def find_by_rank_and_position(rank, position)
|
10
|
-
self.all.find {|i| i.rank == rank && i.position == position.upcase}
|
11
|
-
end
|
12
|
-
|
13
|
-
# def find_by_name(name)
|
14
|
-
# self.all.find {|i| i.name == name}
|
15
|
-
# end
|
16
|
-
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|