nfl_data 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +5 -0
- data/.rubocop.yml +2 -0
- data/README.md +1 -0
- data/Rakefile +1 -1
- data/lib/nfl_data/api/player.rb +5 -9
- data/lib/nfl_data/api/statline.rb +4 -5
- data/lib/nfl_data/api/team.rb +2 -5
- data/lib/nfl_data/models/player.rb +13 -14
- data/lib/nfl_data/models/statline.rb +14 -23
- data/lib/nfl_data/models/team.rb +1 -2
- data/lib/nfl_data/parsers/player_parser.rb +46 -50
- data/lib/nfl_data/parsers/statline_parser.rb +12 -17
- data/lib/nfl_data/parsers/team_parser.rb +21 -18
- data/lib/nfl_data/version.rb +1 -1
- data/nfl_data.gemspec +3 -2
- data/test/nfl_data/models/player_test.rb +7 -3
- data/test/nfl_data/models/statline_test.rb +17 -22
- data/test/nfl_data/models/team_test.rb +0 -2
- data/test/nfl_data/parsers/player_parser_test.rb +18 -12
- data/test/nfl_data/parsers/statline_parser_test.rb +0 -1
- data/test/nfl_data/parsers/team_parser_test.rb +3 -3
- data/test/test_helper.rb +3 -1
- metadata +19 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fde80abd92b5afed0b3c16a9cd3d687387380bd5
|
4
|
+
data.tar.gz: f904cf0f9158c3996494aff4864f1ab3767daa59
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e7d173e1e01bdf293fda1ad9c5c495bb6d7a3f4d5ee0382a680e411241450aaf0c6c762aeb7334a48ec6f403de1e702ceeec7981d29b5478123f9dac38b415e
|
7
|
+
data.tar.gz: fd76a8e7240ae7b46e4c5b084c52138f11eb671de0ae7d8115d926a205e510636563d670e3291ec138e68688e1e594e134baeb729fc57c200944f1059528b365
|
data/.codeclimate.yml
ADDED
data/.rubocop.yml
ADDED
data/README.md
CHANGED
@@ -5,6 +5,7 @@ This gem is for parsing data from NFL.com and returning a JSON blob that can be
|
|
5
5
|
This was written by @mikesells and @thetizzo
|
6
6
|
|
7
7
|
[![Gem Version](https://badge.fury.io/rb/nfl_data.svg)](http://badge.fury.io/rb/nfl_data)
|
8
|
+
[![Code Climate](https://codeclimate.com/github/thetizzo/nfl_data/badges/gpa.svg)](https://codeclimate.com/github/thetizzo/nfl_data)
|
8
9
|
|
9
10
|
## Installation
|
10
11
|
|
data/Rakefile
CHANGED
data/lib/nfl_data/api/player.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
module NflData
|
2
2
|
module API
|
3
3
|
class Player
|
4
|
-
|
5
4
|
def initialize
|
6
5
|
@parser = PlayerParser.new
|
7
6
|
end
|
@@ -11,29 +10,26 @@ module NflData
|
|
11
10
|
end
|
12
11
|
|
13
12
|
class << self
|
14
|
-
|
15
13
|
def get_all
|
16
|
-
|
14
|
+
new.get(:all)
|
17
15
|
end
|
18
16
|
|
19
17
|
def get_quarterbacks
|
20
|
-
|
18
|
+
new.get(:quarterbacks)
|
21
19
|
end
|
22
20
|
|
23
21
|
def get_runningbacks
|
24
|
-
|
22
|
+
new.get(:runningbacks)
|
25
23
|
end
|
26
24
|
|
27
25
|
def get_wide_receivers
|
28
|
-
|
26
|
+
new.get(:wide_receivers)
|
29
27
|
end
|
30
28
|
|
31
29
|
def get_tight_ends
|
32
|
-
|
30
|
+
new.get(:tight_ends)
|
33
31
|
end
|
34
|
-
|
35
32
|
end
|
36
|
-
|
37
33
|
end
|
38
34
|
end
|
39
35
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
module NflData
|
2
2
|
module API
|
3
3
|
class Statline
|
4
|
-
|
5
4
|
def initialize
|
6
5
|
@parser = StatlineParser.new
|
7
6
|
end
|
@@ -12,19 +11,19 @@ module NflData
|
|
12
11
|
|
13
12
|
class << self
|
14
13
|
def get_all(week, year)
|
15
|
-
|
14
|
+
new.get(week, year, :all)
|
16
15
|
end
|
17
16
|
|
18
17
|
def get_passing(week, year)
|
19
|
-
|
18
|
+
new.get(week, year, :passing)
|
20
19
|
end
|
21
20
|
|
22
21
|
def get_rushing(week, year)
|
23
|
-
|
22
|
+
new.get(week, year, :rushing)
|
24
23
|
end
|
25
24
|
|
26
25
|
def get_receiving(week, year)
|
27
|
-
|
26
|
+
new.get(week, year, :receiving)
|
28
27
|
end
|
29
28
|
end
|
30
29
|
end
|
data/lib/nfl_data/api/team.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
module NflData
|
2
2
|
module API
|
3
3
|
class Team
|
4
|
-
|
5
4
|
def initialize
|
6
5
|
@parser = TeamParser.new
|
7
6
|
end
|
@@ -11,15 +10,13 @@ module NflData
|
|
11
10
|
end
|
12
11
|
|
13
12
|
class << self
|
14
|
-
|
15
13
|
def get_all(year)
|
16
|
-
|
14
|
+
new.get(year)
|
17
15
|
end
|
18
16
|
|
19
17
|
def get_all_with_schedule(year)
|
20
|
-
|
18
|
+
new.get(year, true)
|
21
19
|
end
|
22
|
-
|
23
20
|
end
|
24
21
|
end
|
25
22
|
end
|
@@ -1,21 +1,20 @@
|
|
1
1
|
module NflData
|
2
|
-
|
3
2
|
class Player
|
4
|
-
|
3
|
+
ATTRIBUTES = [
|
4
|
+
:first_name, :last_name, :full_name, :position, :number,
|
5
|
+
:status, :team, :nfl_player_id, :picture_link
|
6
|
+
]
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
full_name: full_name,
|
11
|
-
position: position,
|
12
|
-
number: number,
|
13
|
-
status: status,
|
14
|
-
team: team,
|
15
|
-
nfl_player_id: nfl_player_id
|
16
|
-
}
|
8
|
+
attr_accessor(*ATTRIBUTES)
|
9
|
+
|
10
|
+
def initialize(attributes = {})
|
11
|
+
attributes.each { |attr, value| send("#{attr}=", value) }
|
17
12
|
end
|
18
13
|
|
14
|
+
def to_hash
|
15
|
+
attributes_hash = {}
|
16
|
+
ATTRIBUTES.each { |attr| attributes_hash.merge!(attr => send(attr)) }
|
17
|
+
attributes_hash
|
18
|
+
end
|
19
19
|
end
|
20
|
-
|
21
20
|
end
|
@@ -1,30 +1,21 @@
|
|
1
1
|
module NflData
|
2
|
-
|
3
2
|
class Statline
|
4
|
-
|
5
|
-
:
|
6
|
-
:
|
3
|
+
ATTRIBUTES = [
|
4
|
+
:week, :year, :rush_atts, :rush_yards, :rush_tds, :fumbles, :pass_comp,
|
5
|
+
:pass_att, :pass_yards, :pass_tds, :ints, :qb_rating, :receptions,
|
6
|
+
:rec_yards, :rec_tds, :nfl_player_id
|
7
|
+
]
|
8
|
+
|
9
|
+
attr_accessor(*ATTRIBUTES)
|
10
|
+
|
11
|
+
def initialize(attributes = {})
|
12
|
+
attributes.each { |attr, value| send("#{attr}=", value) }
|
13
|
+
end
|
7
14
|
|
8
15
|
def to_hash
|
9
|
-
{
|
10
|
-
|
11
|
-
|
12
|
-
year: year,
|
13
|
-
rush_atts: rush_atts,
|
14
|
-
rush_yards: rush_yards,
|
15
|
-
rush_tds: rush_tds,
|
16
|
-
fumbles: fumbles,
|
17
|
-
pass_comp: pass_comp,
|
18
|
-
pass_att: pass_att,
|
19
|
-
pass_yards: pass_yards,
|
20
|
-
pass_tds: pass_tds,
|
21
|
-
ints: ints,
|
22
|
-
qb_rating: qb_rating,
|
23
|
-
receptions: receptions,
|
24
|
-
rec_yards: rec_yards,
|
25
|
-
rec_tds: rec_tds
|
26
|
-
}
|
16
|
+
attributes_hash = {}
|
17
|
+
ATTRIBUTES.each { |attr| attributes_hash.merge!(attr => send(attr)) }
|
18
|
+
attributes_hash
|
27
19
|
end
|
28
20
|
end
|
29
|
-
|
30
21
|
end
|
data/lib/nfl_data/models/team.rb
CHANGED
@@ -5,84 +5,80 @@ module NflData
|
|
5
5
|
attr_reader :base_url
|
6
6
|
|
7
7
|
def initialize
|
8
|
-
@base_url =
|
8
|
+
@base_url = 'http://www.nfl.com/players/search?category=position&conferenceAbbr=null&playerType=current&conference=ALL&filter='
|
9
9
|
end
|
10
10
|
|
11
11
|
def get_by_position(position)
|
12
|
-
|
13
|
-
when :quarterbacks
|
14
|
-
{ position => get('quarterback') }
|
15
|
-
when :runningbacks
|
16
|
-
{ position => get('runningback') }
|
17
|
-
when :wide_receivers
|
18
|
-
{ position => get('widereceiver') }
|
19
|
-
when :tight_ends
|
20
|
-
{ position => get('tightend') }
|
21
|
-
when :all
|
12
|
+
if position == :all
|
22
13
|
{
|
23
14
|
quarterbacks: get('quarterback'),
|
24
15
|
runningbacks: get('runningback'),
|
25
16
|
wide_receivers: get('widereceiver'),
|
26
17
|
tight_ends: get('tightend')
|
27
18
|
}
|
19
|
+
else
|
20
|
+
# We have to remove the '_' and 's' because the NFL url has
|
21
|
+
# singular position names and all are one word.
|
22
|
+
{ position => get(position.to_s.gsub(/s|_/, '')) }
|
28
23
|
end
|
29
24
|
end
|
30
25
|
|
31
26
|
private
|
32
27
|
|
33
28
|
def get(position)
|
34
|
-
|
35
|
-
url =
|
36
|
-
|
37
|
-
page_num = 1
|
38
|
-
|
39
|
-
count = 100
|
29
|
+
page_number = 1
|
30
|
+
url = "#{@base_url}#{position}&d-447263-p=#{page_number}"
|
31
|
+
return_val = []
|
40
32
|
|
41
33
|
loop do
|
42
|
-
page_num += 1
|
43
34
|
players_found = update_or_create_players(url)
|
44
|
-
|
35
|
+
return_val.push(players_found[1])
|
45
36
|
break if players_found[0] == 0
|
46
|
-
url =
|
47
|
-
|
37
|
+
url = url.chomp(page_number.to_s)
|
38
|
+
page_number += 1
|
39
|
+
url += page_number.to_s
|
48
40
|
end
|
49
41
|
|
50
|
-
|
42
|
+
return_val.flatten.map(&:to_hash)
|
51
43
|
end
|
52
44
|
|
53
45
|
def update_or_create_players(url)
|
54
|
-
# puts "Pulling from url = #{url}"
|
55
46
|
doc = open(url) { |f| Nokogiri(f) }
|
56
47
|
|
57
|
-
#NFL.com stores players in 2 types of rows.
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
all = odds + evens
|
62
|
-
|
63
|
-
players = all.map do |p|
|
64
|
-
player = Player.new
|
65
|
-
elements = p.search("td")
|
66
|
-
player.position = elements[0].inner_text.strip
|
67
|
-
player.number = elements[1].inner_text.strip
|
68
|
-
name = elements[2].inner_text.strip
|
69
|
-
player.status = elements[3].inner_text.strip
|
70
|
-
player.team = make_jacksonville_abbreviation_consistent(elements[12].inner_text.strip)
|
71
|
-
|
72
|
-
#Get NFL.com Unique player id
|
73
|
-
player.nfl_player_id = elements[2].to_s.split('/')[3]
|
74
|
-
|
75
|
-
names = name.split(',')
|
76
|
-
|
77
|
-
player.first_name = names[1].strip
|
78
|
-
player.last_name = names[0].strip
|
79
|
-
|
80
|
-
player.full_name = [player.first_name, player.last_name].join(' ')
|
81
|
-
player
|
82
|
-
end
|
83
|
-
|
48
|
+
# NFL.com stores players in 2 types of rows.
|
49
|
+
# css class = odd or even.
|
50
|
+
all_rows = doc.search('tr.odd') + doc.search('tr.even')
|
51
|
+
players = all_rows.map { |row| parse_player_from_row(row.search('td')) }
|
84
52
|
[players.count, players]
|
85
53
|
end
|
86
54
|
|
55
|
+
def parse_player_from_row(elements)
|
56
|
+
# Get NFL.com Unique player id
|
57
|
+
nfl_player_id = elements[2].to_s.split('/')[3]
|
58
|
+
|
59
|
+
# player id is the only one with complicated parsing so we
|
60
|
+
# can just extract the inner text out of the rest of the elements
|
61
|
+
elements = elements.map(&:inner_text).map(&:strip)
|
62
|
+
names = elements[2].split(',').map(&:strip).reverse
|
63
|
+
|
64
|
+
Player.new(
|
65
|
+
nfl_player_id: nfl_player_id,
|
66
|
+
position: elements[0],
|
67
|
+
number: elements[1],
|
68
|
+
status: elements[3],
|
69
|
+
team: make_jacksonville_abbreviation_consistent(elements[12]),
|
70
|
+
first_name: names[0],
|
71
|
+
last_name: names[1],
|
72
|
+
full_name: names.join(' '),
|
73
|
+
picture_link: get_picture_link(nfl_player_id, names[0], names[1])
|
74
|
+
)
|
75
|
+
end
|
76
|
+
|
77
|
+
def get_picture_link(nfl_player_id, first_name, last_name)
|
78
|
+
return nil if ENV['NFL_DATA_ENV'] == 'test'
|
79
|
+
url = "http://www.nfl.com/player/#{first_name.gsub(/\s/, '')}#{last_name.gsub(/\s/, '')}/#{nfl_player_id}/profile"
|
80
|
+
doc = open(url) { |f| Nokogiri(f) }
|
81
|
+
doc.search('div.player-photo img').first.attributes['src'].value
|
82
|
+
end
|
87
83
|
end
|
88
84
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module NflData
|
2
2
|
class StatlineParser
|
3
|
-
|
4
3
|
def initialize
|
5
4
|
end
|
6
5
|
|
@@ -18,8 +17,9 @@ module NflData
|
|
18
17
|
private
|
19
18
|
|
20
19
|
def get_player_id_from_profile_url(element)
|
21
|
-
old_url =
|
22
|
-
|
20
|
+
old_url = 'http://nfl.com' +
|
21
|
+
element.search('a').first.attributes['href'].value
|
22
|
+
new_url = ''
|
23
23
|
|
24
24
|
begin
|
25
25
|
open(old_url) do |resp|
|
@@ -29,26 +29,22 @@ module NflData
|
|
29
29
|
return nil
|
30
30
|
end
|
31
31
|
|
32
|
-
new_url.gsub(
|
32
|
+
new_url.gsub('http://www.nfl.com', '').to_s.split('/')[3]
|
33
33
|
end
|
34
34
|
|
35
35
|
def grab_week(weeknum, year, stat_type)
|
36
|
-
|
37
|
-
|
38
|
-
seasonUrl = "&season=" + year.to_s
|
39
|
-
catUrl = "&showCategory="
|
40
|
-
|
41
|
-
url = baseUrl + weekUrl + weeknum.to_s + seasonUrl + catUrl + stat_type
|
36
|
+
url = 'http://www.nfl.com/stats/weeklyleaders?type=REG' \
|
37
|
+
"&week=#{weeknum}&season=#{year}&showCategory=#{stat_type}"
|
42
38
|
|
43
39
|
doc = open(url) { |f| Nokogiri(f) }
|
44
40
|
|
45
|
-
odds = doc.search(
|
46
|
-
evens = doc.search(
|
41
|
+
odds = doc.search('tr.odd')
|
42
|
+
evens = doc.search('tr.even')
|
47
43
|
|
48
44
|
all = odds + evens
|
49
45
|
|
50
46
|
all.map do |player_row|
|
51
|
-
elements = player_row.search(
|
47
|
+
elements = player_row.search('td')
|
52
48
|
|
53
49
|
statline = Statline.new
|
54
50
|
|
@@ -56,21 +52,20 @@ module NflData
|
|
56
52
|
statline.week = weeknum
|
57
53
|
statline.year = year
|
58
54
|
|
59
|
-
if
|
55
|
+
if stat_type == 'Rushing'
|
60
56
|
statline.rush_atts = elements[4].inner_text.strip
|
61
57
|
statline.rush_yards = elements[5].inner_text.strip
|
62
58
|
statline.rush_tds = elements[7].inner_text.strip
|
63
59
|
statline.fumbles = elements[8].inner_text.strip
|
64
|
-
elsif
|
60
|
+
elsif stat_type == 'Passing'
|
65
61
|
statline.pass_comp = elements[4].inner_text.strip
|
66
62
|
statline.pass_att = elements[5].inner_text.strip
|
67
63
|
statline.pass_yards = elements[6].inner_text.strip
|
68
64
|
statline.pass_tds = elements[7].inner_text.strip
|
69
65
|
statline.ints = elements[8].inner_text.strip
|
70
|
-
statline.sacks = elements[9].inner_text.strip
|
71
66
|
statline.qb_rating = elements[11].inner_text.strip
|
72
67
|
statline.fumbles = elements [10].inner_text.strip
|
73
|
-
elsif
|
68
|
+
elsif stat_type == 'Receiving'
|
74
69
|
statline.receptions = elements[4].inner_text.strip
|
75
70
|
statline.rec_yards = elements[5].inner_text.strip
|
76
71
|
statline.rec_tds = elements[7].inner_text.strip
|
@@ -5,7 +5,7 @@ module NflData
|
|
5
5
|
attr_reader :base_url
|
6
6
|
|
7
7
|
def initialize
|
8
|
-
@base_url =
|
8
|
+
@base_url = 'http://www.nfl.com/standings?category=league&split=Overall&season='
|
9
9
|
end
|
10
10
|
|
11
11
|
def get_by_year(year, with_schedule)
|
@@ -27,14 +27,15 @@ module NflData
|
|
27
27
|
if href.nil?
|
28
28
|
true
|
29
29
|
else
|
30
|
-
!href.value.start_with?(
|
30
|
+
!href.value.start_with?('/teams/profile?team=')
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
34
|
team_links.map do |link|
|
35
35
|
team = Team.new
|
36
36
|
team.name = link.inner_text.strip
|
37
|
-
|
37
|
+
short_name = link.attribute('href').value.scan(/=(.*)/).flatten.first
|
38
|
+
team.short_name = make_jacksonville_abbreviation_consistent(short_name)
|
38
39
|
team.schedule = get_schedule(team, year) if with_schedule
|
39
40
|
|
40
41
|
team.to_hash
|
@@ -42,7 +43,9 @@ module NflData
|
|
42
43
|
end
|
43
44
|
|
44
45
|
def get_schedule(team, year)
|
45
|
-
url =
|
46
|
+
url = 'http://www.nfl.com/teams/schedule?seasonType=REG&' \
|
47
|
+
"team=#{team.short_name}&season=#{year}"
|
48
|
+
|
46
49
|
schedule = Team::Schedule.new
|
47
50
|
|
48
51
|
doc = open(url) { |f| Nokogiri(f) }
|
@@ -50,25 +53,25 @@ module NflData
|
|
50
53
|
tables = doc.search('table.data-table1')
|
51
54
|
|
52
55
|
tables.each do |table|
|
53
|
-
# Skip any empty tables. They put these in between post season
|
56
|
+
# Skip any empty tables. They put these in between post season
|
57
|
+
# and regular seasons game tables
|
54
58
|
next if table.children.count <= 1
|
55
59
|
title = table.search('tr.thd1 td')
|
56
60
|
|
57
61
|
# Need to check for the Regular Season table and a table with no title
|
58
62
|
# because during the season the NFl splits the games between 2 tables
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
end
|
63
|
+
next unless ['Regular Season', ''].include?(title.inner_text.strip)
|
64
|
+
weeks = table.search('tr.tbdy1')
|
65
|
+
|
66
|
+
weeks.each do |week|
|
67
|
+
game = Team::Schedule::Game.new
|
68
|
+
elements = week.search('td')
|
69
|
+
game.week = elements[0].inner_text.strip
|
70
|
+
game.date = elements[1].inner_text.strip
|
71
|
+
participants = elements[2].search('a')
|
72
|
+
game.opponent = get_opponent(team, participants)
|
73
|
+
game.home_game = home_game?(team, participants)
|
74
|
+
schedule.games << game
|
72
75
|
end
|
73
76
|
end
|
74
77
|
|
data/lib/nfl_data/version.rb
CHANGED
data/nfl_data.gemspec
CHANGED
@@ -11,8 +11,8 @@ Gem::Specification.new do |spec|
|
|
11
11
|
spec.email = ['j.m.taylor1@gmail.com']
|
12
12
|
spec.homepage = 'https://github.com/thetizzo/nfl_data'
|
13
13
|
spec.license = 'MIT'
|
14
|
-
spec.summary =
|
15
|
-
spec.description =
|
14
|
+
spec.summary = 'Parse NFL data like a boss'
|
15
|
+
spec.description = 'Parse NFL data like a boss'
|
16
16
|
|
17
17
|
spec.files = `git ls-files -z`.split("\x0")
|
18
18
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_development_dependency 'minitest', '~> 5.4.1'
|
25
25
|
spec.add_development_dependency 'vcr', '~> 2.9.3'
|
26
26
|
spec.add_development_dependency 'webmock', '~> 1.19.0'
|
27
|
+
spec.add_development_dependency 'rubocop', '~> 0.35.1'
|
27
28
|
|
28
29
|
spec.add_dependency 'nokogiri', '~> 1.6'
|
29
30
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
describe Player do
|
4
|
-
|
5
4
|
before do
|
6
5
|
@player = Player.new
|
7
6
|
end
|
@@ -42,6 +41,10 @@ describe Player do
|
|
42
41
|
@player.must_respond_to :nfl_player_id
|
43
42
|
end
|
44
43
|
|
44
|
+
it 'has a picture_link' do
|
45
|
+
@player.must_respond_to :picture_link
|
46
|
+
end
|
47
|
+
|
45
48
|
describe 'to_hash' do
|
46
49
|
before do
|
47
50
|
@player.first_name = 'John'
|
@@ -52,6 +55,7 @@ describe Player do
|
|
52
55
|
@player.status = 'Retired'
|
53
56
|
@player.team = 'Broncos'
|
54
57
|
@player.nfl_player_id = '123'
|
58
|
+
@player.picture_link = 'google.com'
|
55
59
|
end
|
56
60
|
|
57
61
|
def valid_player_hash
|
@@ -63,13 +67,13 @@ describe Player do
|
|
63
67
|
number: 7,
|
64
68
|
status: 'Retired',
|
65
69
|
team: 'Broncos',
|
66
|
-
nfl_player_id: '123'
|
70
|
+
nfl_player_id: '123',
|
71
|
+
picture_link: 'google.com'
|
67
72
|
}
|
68
73
|
end
|
69
74
|
|
70
75
|
it 'can return itself as hash' do
|
71
76
|
@player.to_hash.must_equal valid_player_hash
|
72
77
|
end
|
73
|
-
|
74
78
|
end
|
75
79
|
end
|
@@ -73,28 +73,24 @@ describe Statline do
|
|
73
73
|
@statline.must_respond_to :nfl_player_id
|
74
74
|
end
|
75
75
|
|
76
|
-
it 'has sacks' do
|
77
|
-
@statline.must_respond_to :sacks
|
78
|
-
end
|
79
|
-
|
80
76
|
describe 'to_hash' do
|
81
77
|
before do
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
78
|
+
@statline.nfl_player_id = '123'
|
79
|
+
@statline.week = 1
|
80
|
+
@statline.year = 2014
|
81
|
+
@statline.rush_atts = 1
|
82
|
+
@statline.rush_yards = 25
|
83
|
+
@statline.rush_tds = 1
|
84
|
+
@statline.fumbles = 0
|
85
|
+
@statline.pass_comp = 1
|
86
|
+
@statline.pass_att = 2
|
87
|
+
@statline.pass_yards = 100
|
88
|
+
@statline.pass_tds = 1
|
89
|
+
@statline.ints = 1
|
90
|
+
@statline.qb_rating = '46.8'
|
91
|
+
@statline.receptions = 2
|
92
|
+
@statline.rec_yards = 25
|
93
|
+
@statline.rec_tds = 1
|
98
94
|
end
|
99
95
|
|
100
96
|
def valid_statline_hash
|
@@ -111,7 +107,7 @@ describe Statline do
|
|
111
107
|
pass_yards: 100,
|
112
108
|
pass_tds: 1,
|
113
109
|
ints: 1,
|
114
|
-
qb_rating:
|
110
|
+
qb_rating: '46.8',
|
115
111
|
receptions: 2,
|
116
112
|
rec_yards: 25,
|
117
113
|
rec_tds: 1
|
@@ -121,6 +117,5 @@ describe Statline do
|
|
121
117
|
it 'can return itself as hash' do
|
122
118
|
@statline.to_hash.must_equal valid_statline_hash
|
123
119
|
end
|
124
|
-
|
125
120
|
end
|
126
121
|
end
|
@@ -10,7 +10,11 @@ describe PlayerParser do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
it 'should know the correct base url' do
|
13
|
-
|
13
|
+
expected_base_url = 'http://www.nfl.com/players/search?category=' \
|
14
|
+
'position&conferenceAbbr=null&playerType=current' \
|
15
|
+
'&conference=ALL&filter='
|
16
|
+
|
17
|
+
@parser.base_url.must_equal expected_base_url
|
14
18
|
end
|
15
19
|
|
16
20
|
describe 'get_by_position' do
|
@@ -19,7 +23,7 @@ describe PlayerParser do
|
|
19
23
|
response = @parser.get_by_position(:quarterbacks)
|
20
24
|
|
21
25
|
response.keys.must_include :quarterbacks
|
22
|
-
response[:quarterbacks].count.must_equal
|
26
|
+
response[:quarterbacks].count.must_equal 118
|
23
27
|
end
|
24
28
|
end
|
25
29
|
|
@@ -28,7 +32,7 @@ describe PlayerParser do
|
|
28
32
|
response = @parser.get_by_position(:runningbacks)
|
29
33
|
|
30
34
|
response.keys.must_include :runningbacks
|
31
|
-
response[:runningbacks].count.must_equal
|
35
|
+
response[:runningbacks].count.must_equal 243
|
32
36
|
end
|
33
37
|
end
|
34
38
|
|
@@ -37,7 +41,7 @@ describe PlayerParser do
|
|
37
41
|
response = @parser.get_by_position(:wide_receivers)
|
38
42
|
|
39
43
|
response.keys.must_include :wide_receivers
|
40
|
-
response[:wide_receivers].count.must_equal
|
44
|
+
response[:wide_receivers].count.must_equal 339
|
41
45
|
end
|
42
46
|
end
|
43
47
|
|
@@ -46,7 +50,7 @@ describe PlayerParser do
|
|
46
50
|
response = @parser.get_by_position(:tight_ends)
|
47
51
|
|
48
52
|
response.keys.must_include :tight_ends
|
49
|
-
response[:tight_ends].count.must_equal
|
53
|
+
response[:tight_ends].count.must_equal 188
|
50
54
|
end
|
51
55
|
end
|
52
56
|
|
@@ -55,10 +59,10 @@ describe PlayerParser do
|
|
55
59
|
response = @parser.get_by_position(:all)
|
56
60
|
|
57
61
|
{
|
58
|
-
quarterbacks:
|
59
|
-
runningbacks:
|
60
|
-
wide_receivers:
|
61
|
-
tight_ends:
|
62
|
+
quarterbacks: 118,
|
63
|
+
runningbacks: 243,
|
64
|
+
wide_receivers: 339,
|
65
|
+
tight_ends: 188
|
62
66
|
}.each do |position, player_count|
|
63
67
|
response.keys.must_include position
|
64
68
|
response[position].count.must_equal player_count
|
@@ -70,10 +74,12 @@ describe PlayerParser do
|
|
70
74
|
VCR.use_cassette('all_players') do
|
71
75
|
response = @parser.get_by_position(:all)
|
72
76
|
|
73
|
-
players =
|
77
|
+
players =
|
78
|
+
[response[:quarterbacks], response[:runningbacks],
|
79
|
+
response[:wide_receivers], response[:tight_ends]].flatten
|
74
80
|
|
75
|
-
players.any? {|player| player[:team] == 'JAX'}.must_equal true
|
76
|
-
players.none? {|player| player[:team] == 'JAC'}.must_equal true
|
81
|
+
players.any? { |player| player[:team] == 'JAX' }.must_equal true
|
82
|
+
players.none? { |player| player[:team] == 'JAC' }.must_equal true
|
77
83
|
end
|
78
84
|
end
|
79
85
|
end
|
@@ -10,7 +10,7 @@ describe TeamParser do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
it 'should know the correct base url' do
|
13
|
-
@parser.base_url.must_equal
|
13
|
+
@parser.base_url.must_equal 'http://www.nfl.com/standings?category=league&split=Overall&season='
|
14
14
|
end
|
15
15
|
|
16
16
|
describe 'get_by_year' do
|
@@ -33,8 +33,8 @@ describe TeamParser do
|
|
33
33
|
it 'should use JAX as the abbreviation for Jacksonville' do
|
34
34
|
VCR.use_cassette('teams_with_schedule') do
|
35
35
|
result = @parser.get_by_year(2014, true)
|
36
|
-
result.any? {|team| team[:short_name] == 'JAX'}.must_equal true
|
37
|
-
result.none? {|team| team[:short_name] == 'JAC'}.must_equal true
|
36
|
+
result.any? { |team| team[:short_name] == 'JAX' }.must_equal true
|
37
|
+
result.none? { |team| team[:short_name] == 'JAC' }.must_equal true
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
data/test/test_helper.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
ENV['NFL_DATA_ENV'] = 'test'
|
2
|
+
|
1
3
|
require 'nfl_data'
|
2
4
|
|
3
5
|
require 'minitest/autorun'
|
@@ -7,6 +9,6 @@ require 'vcr'
|
|
7
9
|
include NflData
|
8
10
|
|
9
11
|
VCR.configure do |c|
|
10
|
-
c.cassette_library_dir = 'test/
|
12
|
+
c.cassette_library_dir = 'test/cassettes'
|
11
13
|
c.hook_into :webmock
|
12
14
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nfl_data
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- thetizzo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 1.19.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.35.1
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.35.1
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: nokogiri
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -102,7 +116,9 @@ executables:
|
|
102
116
|
extensions: []
|
103
117
|
extra_rdoc_files: []
|
104
118
|
files:
|
119
|
+
- ".codeclimate.yml"
|
105
120
|
- ".gitignore"
|
121
|
+
- ".rubocop.yml"
|
106
122
|
- Gemfile
|
107
123
|
- LICENSE.txt
|
108
124
|
- README.md
|
@@ -151,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
151
167
|
version: '0'
|
152
168
|
requirements: []
|
153
169
|
rubyforge_project:
|
154
|
-
rubygems_version: 2.4.5
|
170
|
+
rubygems_version: 2.4.5.1
|
155
171
|
signing_key:
|
156
172
|
specification_version: 4
|
157
173
|
summary: Parse NFL data like a boss
|