nfl_data 0.0.10 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.envrc +7 -0
- data/.gitignore +3 -3
- data/.rspec +1 -0
- data/.standard.yml +2 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.md +7 -0
- data/Gemfile +1 -1
- data/README.md +94 -21
- data/Rakefile +5 -6
- data/bin/console +1 -1
- data/bin/setup +8 -0
- data/lib/nfl_data.rb +10 -18
- data/lib/nfl_data/api/player.rb +8 -30
- data/lib/nfl_data/api/schedule.rb +19 -0
- data/lib/nfl_data/api/statline.rb +8 -23
- data/lib/nfl_data/models/game.rb +5 -0
- data/lib/nfl_data/models/player.rb +11 -19
- data/lib/nfl_data/models/schedule.rb +12 -0
- data/lib/nfl_data/models/statline.rb +18 -28
- data/lib/nfl_data/my_sports_feeds/client.rb +45 -0
- data/lib/nfl_data/my_sports_feeds/players_feed.rb +18 -0
- data/lib/nfl_data/my_sports_feeds/seasonal_games_feed.rb +22 -0
- data/lib/nfl_data/my_sports_feeds/weekly_player_gamelogs.rb +21 -0
- data/lib/nfl_data/parsers/player_parser.rb +21 -81
- data/lib/nfl_data/parsers/schedule_parser.rb +20 -0
- data/lib/nfl_data/parsers/statline_parser.rb +27 -76
- data/lib/nfl_data/version.rb +1 -1
- data/nfl_data.gemspec +23 -21
- data/spec/api/player_spec.rb +24 -0
- data/spec/api/schedule_spec.rb +20 -0
- data/spec/api/statline_spec.rb +31 -0
- data/spec/models/game_spec.rb +15 -0
- data/spec/models/player_spec.rb +42 -0
- data/spec/models/schedule_spec.rb +17 -0
- data/spec/models/statline_spec.rb +63 -0
- data/spec/my_sports_feeds/client_spec.rb +17 -0
- data/spec/my_sports_feeds/players_feed_spec.rb +49 -0
- data/spec/my_sports_feeds/seasonal_games_feed_spec.rb +41 -0
- data/spec/my_sports_feeds/weekly_player_gamelogs_spec.rb +144 -0
- data/spec/parsers/player_parser_spec.rb +63 -0
- data/spec/parsers/schedule_parser_spec.rb +41 -0
- data/spec/parsers/statline_parser_spec.rb +68 -0
- data/spec/spec_helper.rb +55 -0
- metadata +107 -45
- data/lib/nfl_data/api/team.rb +0 -26
- data/lib/nfl_data/models/team.rb +0 -39
- data/lib/nfl_data/parsers/parser_helper.rb +0 -6
- data/lib/nfl_data/parsers/team_parser.rb +0 -91
- data/test/nfl_data/api/player_test.rb +0 -25
- data/test/nfl_data/api/statline_test.rb +0 -21
- data/test/nfl_data/api/team_test.rb +0 -13
- data/test/nfl_data/models/player_test.rb +0 -75
- data/test/nfl_data/models/statline_test.rb +0 -126
- data/test/nfl_data/models/team_test.rb +0 -45
- data/test/nfl_data/parsers/player_parser_test.rb +0 -80
- data/test/nfl_data/parsers/statline_parser_test.rb +0 -35
- data/test/nfl_data/parsers/team_parser_test.rb +0 -41
- data/test/test_helper.rb +0 -12
data/lib/nfl_data/api/team.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
module NflData
|
2
|
-
module API
|
3
|
-
class Team
|
4
|
-
|
5
|
-
def initialize
|
6
|
-
@parser = TeamParser.new
|
7
|
-
end
|
8
|
-
|
9
|
-
def get(year, with_schedule = false)
|
10
|
-
@parser.get_by_year(year, with_schedule).to_json
|
11
|
-
end
|
12
|
-
|
13
|
-
class << self
|
14
|
-
|
15
|
-
def get_all(year)
|
16
|
-
self.new.get(year)
|
17
|
-
end
|
18
|
-
|
19
|
-
def get_all_with_schedule(year)
|
20
|
-
self.new.get(year, true)
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
data/lib/nfl_data/models/team.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
module NflData
|
2
|
-
class Team
|
3
|
-
attr_accessor :name, :short_name, :schedule
|
4
|
-
|
5
|
-
def to_hash
|
6
|
-
{
|
7
|
-
name: name,
|
8
|
-
short_name: short_name,
|
9
|
-
schedule: schedule.nil? ? [] : schedule.to_hash
|
10
|
-
}
|
11
|
-
end
|
12
|
-
|
13
|
-
class Schedule
|
14
|
-
attr_accessor :games
|
15
|
-
|
16
|
-
def initialize
|
17
|
-
@games = []
|
18
|
-
end
|
19
|
-
|
20
|
-
def to_hash
|
21
|
-
@games.map { |game| game.to_hash }
|
22
|
-
end
|
23
|
-
|
24
|
-
class Game
|
25
|
-
attr_accessor :week, :opponent, :date, :home_game
|
26
|
-
|
27
|
-
def to_hash
|
28
|
-
{
|
29
|
-
week: week,
|
30
|
-
opponent: opponent,
|
31
|
-
date: date,
|
32
|
-
home_game: home_game
|
33
|
-
}
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
@@ -1,91 +0,0 @@
|
|
1
|
-
module NflData
|
2
|
-
class TeamParser
|
3
|
-
include ParserHelper
|
4
|
-
|
5
|
-
attr_reader :base_url
|
6
|
-
|
7
|
-
def initialize
|
8
|
-
@base_url = "http://www.nfl.com/standings?category=league&split=Overall&season="
|
9
|
-
end
|
10
|
-
|
11
|
-
def get_by_year(year, with_schedule)
|
12
|
-
get(year, with_schedule)
|
13
|
-
end
|
14
|
-
|
15
|
-
private
|
16
|
-
|
17
|
-
def get(year, with_schedule)
|
18
|
-
url = @base_url + "#{year}-REG"
|
19
|
-
|
20
|
-
doc = open(url) { |f| Nokogiri(f) }
|
21
|
-
|
22
|
-
all_links = doc.search('a').to_a
|
23
|
-
|
24
|
-
team_links = all_links.reject do |link|
|
25
|
-
href = link.attribute('href')
|
26
|
-
|
27
|
-
if href.nil?
|
28
|
-
true
|
29
|
-
else
|
30
|
-
!href.value.start_with?("/teams/profile?team=")
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
team_links.map do |link|
|
35
|
-
team = Team.new
|
36
|
-
team.name = link.inner_text.strip
|
37
|
-
team.short_name = make_jacksonville_abbreviation_consistent(link.attribute('href').value.scan(/=(.*)/).flatten.first)
|
38
|
-
team.schedule = get_schedule(team, year) if with_schedule
|
39
|
-
|
40
|
-
team.to_hash
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def get_schedule(team, year)
|
45
|
-
url = "http://www.nfl.com/teams/schedule?seasonType=REG&team=#{team.short_name}&season=#{year}"
|
46
|
-
schedule = Team::Schedule.new
|
47
|
-
|
48
|
-
doc = open(url) { |f| Nokogiri(f) }
|
49
|
-
|
50
|
-
tables = doc.search('table.data-table1')
|
51
|
-
|
52
|
-
tables.each do |table|
|
53
|
-
# Skip any empty tables. They put these in between post season and regular seasons game tables
|
54
|
-
next if table.children.count <= 1
|
55
|
-
title = table.search('tr.thd1 td')
|
56
|
-
|
57
|
-
# Need to check for the Regular Season table and a table with no title
|
58
|
-
# because during the season the NFl splits the games between 2 tables
|
59
|
-
if ['Regular Season', ''].include?(title.inner_text.strip)
|
60
|
-
weeks = table.search('tr.tbdy1')
|
61
|
-
|
62
|
-
weeks.each do |week|
|
63
|
-
game = Team::Schedule::Game.new
|
64
|
-
elements = week.search('td')
|
65
|
-
game.week = elements[0].inner_text.strip
|
66
|
-
game.date = elements[1].inner_text.strip
|
67
|
-
participants = elements[2].search('a')
|
68
|
-
game.opponent = get_opponent(team, participants)
|
69
|
-
game.home_game = home_game?(team, participants)
|
70
|
-
schedule.games << game
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
schedule
|
76
|
-
end
|
77
|
-
|
78
|
-
def get_opponent(team, participants)
|
79
|
-
return nil if participants[0].nil?
|
80
|
-
p1 = participants[0].inner_text.strip
|
81
|
-
return participants[1].inner_text.strip if team.short_name == p1
|
82
|
-
p1
|
83
|
-
end
|
84
|
-
|
85
|
-
def home_game?(team, participants)
|
86
|
-
return nil if participants[0].nil?
|
87
|
-
home_team = participants[1].inner_text.strip
|
88
|
-
home_team == team.short_name
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
describe API::Player do
|
4
|
-
subject { API::Player }
|
5
|
-
|
6
|
-
it 'should respond to get_all' do
|
7
|
-
subject.must_respond_to :get_all
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'should respond to get_quarterbacks' do
|
11
|
-
subject.must_respond_to :get_quarterbacks
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'should respond to get_runningbacks' do
|
15
|
-
subject.must_respond_to :get_runningbacks
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'should respond to get_wide_receivers' do
|
19
|
-
subject.must_respond_to :get_wide_receivers
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'should respond to get_tight_ends' do
|
23
|
-
subject.must_respond_to :get_tight_ends
|
24
|
-
end
|
25
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
describe API::Statline do
|
4
|
-
subject { API::Statline }
|
5
|
-
|
6
|
-
it 'should respond to get_all_by_week_and_year' do
|
7
|
-
subject.must_respond_to :get_all
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'should respond to get_passing_by_week_and_year' do
|
11
|
-
subject.must_respond_to :get_passing
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'should respond to get_rushing_by_week_and_year' do
|
15
|
-
subject.must_respond_to :get_rushing
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'should respond to get_receiving_by_week_and_year' do
|
19
|
-
subject.must_respond_to :get_receiving
|
20
|
-
end
|
21
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
describe API::Team do
|
4
|
-
subject { API::Team }
|
5
|
-
|
6
|
-
it 'should respond to get_all' do
|
7
|
-
subject.must_respond_to :get_all
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'should response to get_all_with_schedule' do
|
11
|
-
subject.must_respond_to :get_all_with_schedule
|
12
|
-
end
|
13
|
-
end
|
@@ -1,75 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
describe Player do
|
4
|
-
|
5
|
-
before do
|
6
|
-
@player = Player.new
|
7
|
-
end
|
8
|
-
|
9
|
-
after do
|
10
|
-
@player = nil
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'has a first name' do
|
14
|
-
@player.must_respond_to :first_name
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'has a last name' do
|
18
|
-
@player.must_respond_to :last_name
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'has a full name' do
|
22
|
-
@player.must_respond_to :full_name
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'has a position' do
|
26
|
-
@player.must_respond_to :position
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'has a number' do
|
30
|
-
@player.must_respond_to :number
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'has a status' do
|
34
|
-
@player.must_respond_to :status
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'has a team' do
|
38
|
-
@player.must_respond_to :team
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'has an NFL player ID' do
|
42
|
-
@player.must_respond_to :nfl_player_id
|
43
|
-
end
|
44
|
-
|
45
|
-
describe 'to_hash' do
|
46
|
-
before do
|
47
|
-
@player.first_name = 'John'
|
48
|
-
@player.last_name = 'Elway'
|
49
|
-
@player.position = 'QB'
|
50
|
-
@player.full_name = 'John Elway'
|
51
|
-
@player.number = 7
|
52
|
-
@player.status = 'Retired'
|
53
|
-
@player.team = 'Broncos'
|
54
|
-
@player.nfl_player_id = '123'
|
55
|
-
end
|
56
|
-
|
57
|
-
def valid_player_hash
|
58
|
-
{
|
59
|
-
first_name: 'John',
|
60
|
-
last_name: 'Elway',
|
61
|
-
full_name: 'John Elway',
|
62
|
-
position: 'QB',
|
63
|
-
number: 7,
|
64
|
-
status: 'Retired',
|
65
|
-
team: 'Broncos',
|
66
|
-
nfl_player_id: '123'
|
67
|
-
}
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'can return itself as hash' do
|
71
|
-
@player.to_hash.must_equal valid_player_hash
|
72
|
-
end
|
73
|
-
|
74
|
-
end
|
75
|
-
end
|
@@ -1,126 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
describe Statline do
|
4
|
-
before do
|
5
|
-
@statline = Statline.new
|
6
|
-
end
|
7
|
-
|
8
|
-
after do
|
9
|
-
@statline = nil
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'has a week' do
|
13
|
-
@statline.must_respond_to :week
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'has a year' do
|
17
|
-
@statline.must_respond_to :year
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'has rush attempts' do
|
21
|
-
@statline.must_respond_to :rush_atts
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'has rush yards' do
|
25
|
-
@statline.must_respond_to :rush_yards
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'has rush touchdowns' do
|
29
|
-
@statline.must_respond_to :rush_tds
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'has fumbles' do
|
33
|
-
@statline.must_respond_to :fumbles
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'has pass completions' do
|
37
|
-
@statline.must_respond_to :pass_comp
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'has pass attempts' do
|
41
|
-
@statline.must_respond_to :pass_att
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'has pass yards' do
|
45
|
-
@statline.must_respond_to :pass_yards
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'has pass touchdowns' do
|
49
|
-
@statline.must_respond_to :pass_tds
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'has interceptions' do
|
53
|
-
@statline.must_respond_to :ints
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'has QB rating' do
|
57
|
-
@statline.must_respond_to :qb_rating
|
58
|
-
end
|
59
|
-
|
60
|
-
it 'has receptions' do
|
61
|
-
@statline.must_respond_to :receptions
|
62
|
-
end
|
63
|
-
|
64
|
-
it 'has receiving yards' do
|
65
|
-
@statline.must_respond_to :rec_yards
|
66
|
-
end
|
67
|
-
|
68
|
-
it 'has receiving touchdowns' do
|
69
|
-
@statline.must_respond_to :rec_tds
|
70
|
-
end
|
71
|
-
|
72
|
-
it 'has an NFL player id' do
|
73
|
-
@statline.must_respond_to :nfl_player_id
|
74
|
-
end
|
75
|
-
|
76
|
-
it 'has sacks' do
|
77
|
-
@statline.must_respond_to :sacks
|
78
|
-
end
|
79
|
-
|
80
|
-
describe 'to_hash' do
|
81
|
-
before do
|
82
|
-
@statline.nfl_player_id = '123'
|
83
|
-
@statline.week = 1
|
84
|
-
@statline.year = 2014
|
85
|
-
@statline.rush_atts = 1
|
86
|
-
@statline.rush_yards = 25
|
87
|
-
@statline.rush_tds = 1
|
88
|
-
@statline.fumbles = 0
|
89
|
-
@statline.pass_comp = 1
|
90
|
-
@statline.pass_att = 2
|
91
|
-
@statline.pass_yards = 100
|
92
|
-
@statline.pass_tds = 1
|
93
|
-
@statline.ints = 1
|
94
|
-
@statline.qb_rating = "46.8"
|
95
|
-
@statline.receptions = 2
|
96
|
-
@statline.rec_yards = 25
|
97
|
-
@statline.rec_tds = 1
|
98
|
-
end
|
99
|
-
|
100
|
-
def valid_statline_hash
|
101
|
-
{
|
102
|
-
nfl_player_id: '123',
|
103
|
-
week: 1,
|
104
|
-
year: 2014,
|
105
|
-
rush_atts: 1,
|
106
|
-
rush_yards: 25,
|
107
|
-
rush_tds: 1,
|
108
|
-
fumbles: 0,
|
109
|
-
pass_comp: 1,
|
110
|
-
pass_att: 2,
|
111
|
-
pass_yards: 100,
|
112
|
-
pass_tds: 1,
|
113
|
-
ints: 1,
|
114
|
-
qb_rating: "46.8",
|
115
|
-
receptions: 2,
|
116
|
-
rec_yards: 25,
|
117
|
-
rec_tds: 1
|
118
|
-
}
|
119
|
-
end
|
120
|
-
|
121
|
-
it 'can return itself as hash' do
|
122
|
-
@statline.to_hash.must_equal valid_statline_hash
|
123
|
-
end
|
124
|
-
|
125
|
-
end
|
126
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
describe Team do
|
4
|
-
|
5
|
-
before do
|
6
|
-
@team = Team.new
|
7
|
-
end
|
8
|
-
|
9
|
-
after do
|
10
|
-
@team = nil
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'has a name' do
|
14
|
-
@team.must_respond_to :name
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'has a short name' do
|
18
|
-
@team.must_respond_to :short_name
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'has a schedule' do
|
22
|
-
@team.must_respond_to :schedule
|
23
|
-
end
|
24
|
-
|
25
|
-
describe 'to_hash' do
|
26
|
-
before do
|
27
|
-
@team.name = 'Denver Broncos'
|
28
|
-
@team.short_name = 'DEN'
|
29
|
-
@team.schedule = Team::Schedule.new
|
30
|
-
end
|
31
|
-
|
32
|
-
def valid_player_hash
|
33
|
-
{
|
34
|
-
name: 'Denver Broncos',
|
35
|
-
short_name: 'DEN',
|
36
|
-
schedule: []
|
37
|
-
}
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'can return itself as hash' do
|
41
|
-
@team.to_hash.must_equal valid_player_hash
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
45
|
-
end
|