nfl_data 0.0.14 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- 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 -22
- data/Rakefile +5 -6
- data/bin/console +1 -1
- data/bin/setup +8 -0
- data/lib/nfl_data.rb +10 -19
- data/lib/nfl_data/api/player.rb +8 -26
- data/lib/nfl_data/api/schedule.rb +19 -0
- data/lib/nfl_data/api/statline.rb +8 -22
- data/lib/nfl_data/models/game.rb +5 -0
- data/lib/nfl_data/models/player.rb +11 -18
- data/lib/nfl_data/models/schedule.rb +12 -0
- data/lib/nfl_data/models/statline.rb +18 -19
- 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 +20 -93
- data/lib/nfl_data/parsers/schedule_parser.rb +20 -0
- data/lib/nfl_data/parsers/statline_parser.rb +27 -71
- data/lib/nfl_data/version.rb +1 -1
- data/nfl_data.gemspec +23 -23
- 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 +83 -52
- data/.codeclimate.yml +0 -5
- data/.rubocop.yml +0 -2
- data/lib/nfl_data/api/team.rb +0 -23
- data/lib/nfl_data/models/team.rb +0 -38
- data/lib/nfl_data/parsers/data/teams.rb +0 -36
- data/lib/nfl_data/parsers/parser_helper.rb +0 -6
- data/lib/nfl_data/parsers/team_parser.rb +0 -76
- 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 -81
- data/test/nfl_data/models/statline_test.rb +0 -121
- data/test/nfl_data/models/team_test.rb +0 -43
- data/test/nfl_data/parsers/player_parser_test.rb +0 -81
- data/test/nfl_data/parsers/statline_parser_test.rb +0 -34
- data/test/nfl_data/parsers/team_parser_test.rb +0 -37
- data/test/test_helper.rb +0 -14
data/.codeclimate.yml
DELETED
data/.rubocop.yml
DELETED
data/lib/nfl_data/api/team.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
module NflData
|
2
|
-
module API
|
3
|
-
class Team
|
4
|
-
def initialize
|
5
|
-
@parser = TeamParser.new
|
6
|
-
end
|
7
|
-
|
8
|
-
def get(year, with_schedule = false)
|
9
|
-
@parser.get_by_year(year, with_schedule).to_json
|
10
|
-
end
|
11
|
-
|
12
|
-
class << self
|
13
|
-
def get_all(year)
|
14
|
-
new.get(year)
|
15
|
-
end
|
16
|
-
|
17
|
-
def get_all_with_schedule(year)
|
18
|
-
new.get(year, true)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
data/lib/nfl_data/models/team.rb
DELETED
@@ -1,38 +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(&: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
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
module Teams
|
2
|
-
TEAMS = {
|
3
|
-
'ARI' => 'Arizona Cardinals',
|
4
|
-
'ATL' => 'Atlanta Falcons',
|
5
|
-
'BAL' => 'Baltimore Ravens',
|
6
|
-
'BUF' => 'Buffalo Bills',
|
7
|
-
'CAR' => 'Carolina Panthers',
|
8
|
-
'CHI' => 'Chicago Bears',
|
9
|
-
'CIN' => 'Cincinnati Bengals',
|
10
|
-
'CLE' => 'Cleveland Browns',
|
11
|
-
'DAL' => 'Dallas Cowboys',
|
12
|
-
'DEN' => 'Denver Broncos',
|
13
|
-
'DET' => 'Detroit Lions',
|
14
|
-
'GB' => 'Green Bay Packers',
|
15
|
-
'HOU' => 'Houston Texans',
|
16
|
-
'IND' => 'Indianapolis Colts',
|
17
|
-
'JAX' => 'Jacksonville Jaguars',
|
18
|
-
'KC' => 'Kansas City Chiefs',
|
19
|
-
'LA' => 'Los Angeles Rams',
|
20
|
-
'LAC' => 'Los Angeles Chargers',
|
21
|
-
'MIA' => 'Miami Dolphins',
|
22
|
-
'MIN' => 'Minnesota Vikings',
|
23
|
-
'NE' => 'New England Patriots',
|
24
|
-
'NO' => 'New Orleans Saints',
|
25
|
-
'NYG' => 'New York Giants',
|
26
|
-
'NYJ' => 'New York Jets',
|
27
|
-
'OAK' => 'Oakland Raiders',
|
28
|
-
'PHI' => 'Philadelphia Eagles',
|
29
|
-
'PIT' => 'Pittsburgh Steelers',
|
30
|
-
'SEA' => 'Seattle Seahawks',
|
31
|
-
'SF' => 'San Francisco 49ers',
|
32
|
-
'TB' => 'Tampa Bay Buccaneers',
|
33
|
-
'TEN' => 'Tennessee Titans',
|
34
|
-
'WAS' => 'Washington Redskins'
|
35
|
-
}
|
36
|
-
end
|
@@ -1,76 +0,0 @@
|
|
1
|
-
module NflData
|
2
|
-
class TeamParser
|
3
|
-
include Teams
|
4
|
-
|
5
|
-
attr_reader :base_url
|
6
|
-
|
7
|
-
def initialize
|
8
|
-
end
|
9
|
-
|
10
|
-
def get_by_year(year, with_schedule)
|
11
|
-
get(year, with_schedule)
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
def get(year, with_schedule)
|
17
|
-
TEAMS.map do |short_name, team_name|
|
18
|
-
team = Team.new
|
19
|
-
team.name = team_name
|
20
|
-
team.short_name = short_name
|
21
|
-
team.schedule = get_schedule(team, year) if with_schedule
|
22
|
-
|
23
|
-
team.to_hash
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def get_schedule(team, year)
|
28
|
-
url = 'http://www.nfl.com/teams/schedule?seasonType=REG&' \
|
29
|
-
"team=#{team.short_name}&season=#{year}"
|
30
|
-
|
31
|
-
schedule = Team::Schedule.new
|
32
|
-
|
33
|
-
doc = open(url) { |f| Nokogiri(f) }
|
34
|
-
|
35
|
-
tables = doc.search('table.data-table1')
|
36
|
-
|
37
|
-
tables.each do |table|
|
38
|
-
# Skip any empty tables. They put these in between post season
|
39
|
-
# and regular seasons game tables
|
40
|
-
next if table.children.count <= 1
|
41
|
-
title = table.search('tr.thd1 td')
|
42
|
-
|
43
|
-
# Need to check for the Regular Season table and a table with no title
|
44
|
-
# because during the season the NFl splits the games between 2 tables
|
45
|
-
next unless ['Regular Season', ''].include?(title.inner_text.strip)
|
46
|
-
weeks = table.search('tr.tbdy1')
|
47
|
-
|
48
|
-
weeks.each do |week|
|
49
|
-
game = Team::Schedule::Game.new
|
50
|
-
elements = week.search('td')
|
51
|
-
game.week = elements[0].inner_text.strip
|
52
|
-
game.date = elements[1].inner_text.strip
|
53
|
-
participants = elements[2].search('a')
|
54
|
-
game.opponent = get_opponent(team, participants)
|
55
|
-
game.home_game = home_game?(team, participants)
|
56
|
-
schedule.games << game
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
schedule
|
61
|
-
end
|
62
|
-
|
63
|
-
def get_opponent(team, participants)
|
64
|
-
return nil if participants[0].nil?
|
65
|
-
p1 = participants[0].inner_text.strip
|
66
|
-
return participants[1].inner_text.strip if team.short_name == p1
|
67
|
-
p1
|
68
|
-
end
|
69
|
-
|
70
|
-
def home_game?(team, participants)
|
71
|
-
return nil if participants[0].nil?
|
72
|
-
home_team = participants[1].inner_text.strip
|
73
|
-
home_team == team.short_name
|
74
|
-
end
|
75
|
-
end
|
76
|
-
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,81 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
describe Player do
|
4
|
-
before do
|
5
|
-
@player = Player.new
|
6
|
-
end
|
7
|
-
|
8
|
-
after do
|
9
|
-
@player = nil
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'has a first name' do
|
13
|
-
@player.must_respond_to :first_name
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'has a last name' do
|
17
|
-
@player.must_respond_to :last_name
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'has a full name' do
|
21
|
-
@player.must_respond_to :full_name
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'has a position' do
|
25
|
-
@player.must_respond_to :position
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'has a number' do
|
29
|
-
@player.must_respond_to :number
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'has a status' do
|
33
|
-
@player.must_respond_to :status
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'has a team' do
|
37
|
-
@player.must_respond_to :team
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'has an NFL player ID' do
|
41
|
-
@player.must_respond_to :nfl_player_id
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'has a picture_link' do
|
45
|
-
@player.must_respond_to :picture_link
|
46
|
-
end
|
47
|
-
|
48
|
-
describe 'to_hash' do
|
49
|
-
before do
|
50
|
-
@player.first_name = 'John'
|
51
|
-
@player.last_name = 'Elway'
|
52
|
-
@player.position = 'QB'
|
53
|
-
@player.full_name = 'John Elway'
|
54
|
-
@player.number = 7
|
55
|
-
@player.status = 'Retired'
|
56
|
-
@player.team = 'Broncos'
|
57
|
-
@player.nfl_player_id = '123'
|
58
|
-
@player.picture_link = 'google.com'
|
59
|
-
@player.profile_link = 'espn.com'
|
60
|
-
end
|
61
|
-
|
62
|
-
def valid_player_hash
|
63
|
-
{
|
64
|
-
first_name: 'John',
|
65
|
-
last_name: 'Elway',
|
66
|
-
full_name: 'John Elway',
|
67
|
-
position: 'QB',
|
68
|
-
number: 7,
|
69
|
-
status: 'Retired',
|
70
|
-
team: 'Broncos',
|
71
|
-
nfl_player_id: '123',
|
72
|
-
picture_link: 'google.com',
|
73
|
-
profile_link: 'espn.com'
|
74
|
-
}
|
75
|
-
end
|
76
|
-
|
77
|
-
it 'can return itself as hash' do
|
78
|
-
@player.to_hash.must_equal valid_player_hash
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
@@ -1,121 +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
|
-
describe 'to_hash' do
|
77
|
-
before do
|
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
|
94
|
-
end
|
95
|
-
|
96
|
-
def valid_statline_hash
|
97
|
-
{
|
98
|
-
nfl_player_id: '123',
|
99
|
-
week: 1,
|
100
|
-
year: 2014,
|
101
|
-
rush_atts: 1,
|
102
|
-
rush_yards: 25,
|
103
|
-
rush_tds: 1,
|
104
|
-
fumbles: 0,
|
105
|
-
pass_comp: 1,
|
106
|
-
pass_att: 2,
|
107
|
-
pass_yards: 100,
|
108
|
-
pass_tds: 1,
|
109
|
-
ints: 1,
|
110
|
-
qb_rating: '46.8',
|
111
|
-
receptions: 2,
|
112
|
-
rec_yards: 25,
|
113
|
-
rec_tds: 1
|
114
|
-
}
|
115
|
-
end
|
116
|
-
|
117
|
-
it 'can return itself as hash' do
|
118
|
-
@statline.to_hash.must_equal valid_statline_hash
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|