nfl_data 0.0.11 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. checksums.yaml +5 -5
  2. data/.envrc +7 -0
  3. data/.gitignore +3 -3
  4. data/.rspec +1 -0
  5. data/.standard.yml +2 -0
  6. data/.travis.yml +6 -0
  7. data/CHANGELOG.md +11 -0
  8. data/Gemfile +1 -1
  9. data/README.md +94 -22
  10. data/Rakefile +5 -6
  11. data/bin/console +1 -1
  12. data/bin/setup +8 -0
  13. data/lib/nfl_data.rb +9 -18
  14. data/lib/nfl_data/api/player.rb +8 -26
  15. data/lib/nfl_data/api/schedule.rb +19 -0
  16. data/lib/nfl_data/api/statline.rb +8 -22
  17. data/lib/nfl_data/game.rb +5 -0
  18. data/lib/nfl_data/my_sports_feeds/client.rb +45 -0
  19. data/lib/nfl_data/my_sports_feeds/players_feed.rb +18 -0
  20. data/lib/nfl_data/my_sports_feeds/seasonal_games_feed.rb +22 -0
  21. data/lib/nfl_data/my_sports_feeds/weekly_player_gamelogs.rb +21 -0
  22. data/lib/nfl_data/parsers/player_parser.rb +21 -77
  23. data/lib/nfl_data/parsers/schedule_parser.rb +20 -0
  24. data/lib/nfl_data/parsers/statline_parser.rb +27 -71
  25. data/lib/nfl_data/player.rb +13 -0
  26. data/lib/nfl_data/schedule.rb +12 -0
  27. data/lib/nfl_data/statline.rb +20 -0
  28. data/lib/nfl_data/version.rb +1 -1
  29. data/nfl_data.gemspec +23 -22
  30. data/spec/api/player_spec.rb +24 -0
  31. data/spec/api/schedule_spec.rb +20 -0
  32. data/spec/api/statline_spec.rb +31 -0
  33. data/spec/models/game_spec.rb +15 -0
  34. data/spec/models/player_spec.rb +42 -0
  35. data/spec/models/schedule_spec.rb +17 -0
  36. data/spec/models/statline_spec.rb +63 -0
  37. data/spec/my_sports_feeds/client_spec.rb +17 -0
  38. data/spec/my_sports_feeds/players_feed_spec.rb +50 -0
  39. data/spec/my_sports_feeds/seasonal_games_feed_spec.rb +41 -0
  40. data/spec/my_sports_feeds/weekly_player_gamelogs_spec.rb +144 -0
  41. data/spec/parsers/player_parser_spec.rb +63 -0
  42. data/spec/parsers/schedule_parser_spec.rb +41 -0
  43. data/spec/parsers/statline_parser_spec.rb +68 -0
  44. data/spec/spec_helper.rb +55 -0
  45. metadata +98 -52
  46. data/.codeclimate.yml +0 -5
  47. data/.rubocop.yml +0 -2
  48. data/lib/nfl_data/api/team.rb +0 -23
  49. data/lib/nfl_data/models/player.rb +0 -20
  50. data/lib/nfl_data/models/statline.rb +0 -21
  51. data/lib/nfl_data/models/team.rb +0 -38
  52. data/lib/nfl_data/parsers/parser_helper.rb +0 -6
  53. data/lib/nfl_data/parsers/team_parser.rb +0 -94
  54. data/test/nfl_data/api/player_test.rb +0 -25
  55. data/test/nfl_data/api/statline_test.rb +0 -21
  56. data/test/nfl_data/api/team_test.rb +0 -13
  57. data/test/nfl_data/models/player_test.rb +0 -79
  58. data/test/nfl_data/models/statline_test.rb +0 -121
  59. data/test/nfl_data/models/team_test.rb +0 -43
  60. data/test/nfl_data/parsers/player_parser_test.rb +0 -86
  61. data/test/nfl_data/parsers/statline_parser_test.rb +0 -34
  62. data/test/nfl_data/parsers/team_parser_test.rb +0 -41
  63. data/test/test_helper.rb +0 -14
@@ -1,20 +0,0 @@
1
- module NflData
2
- class Player
3
- ATTRIBUTES = [
4
- :first_name, :last_name, :full_name, :position, :number,
5
- :status, :team, :nfl_player_id, :picture_link
6
- ]
7
-
8
- attr_accessor(*ATTRIBUTES)
9
-
10
- def initialize(attributes = {})
11
- attributes.each { |attr, value| send("#{attr}=", value) }
12
- end
13
-
14
- def to_hash
15
- attributes_hash = {}
16
- ATTRIBUTES.each { |attr| attributes_hash.merge!(attr => send(attr)) }
17
- attributes_hash
18
- end
19
- end
20
- end
@@ -1,21 +0,0 @@
1
- module NflData
2
- class Statline
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
14
-
15
- def to_hash
16
- attributes_hash = {}
17
- ATTRIBUTES.each { |attr| attributes_hash.merge!(attr => send(attr)) }
18
- attributes_hash
19
- end
20
- end
21
- end
@@ -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,6 +0,0 @@
1
- module ParserHelper
2
- def make_jacksonville_abbreviation_consistent(team_name)
3
- # Use JAX because schedule pages use JAX and it's easier to fix it here
4
- team_name == 'JAC' ? 'JAX' : team_name
5
- end
6
- end
@@ -1,94 +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
- short_name = link.attribute('href').value.scan(/=(.*)/).flatten.first
38
- team.short_name = make_jacksonville_abbreviation_consistent(short_name)
39
- team.schedule = get_schedule(team, year) if with_schedule
40
-
41
- team.to_hash
42
- end
43
- end
44
-
45
- def get_schedule(team, year)
46
- url = 'http://www.nfl.com/teams/schedule?seasonType=REG&' \
47
- "team=#{team.short_name}&season=#{year}"
48
-
49
- schedule = Team::Schedule.new
50
-
51
- doc = open(url) { |f| Nokogiri(f) }
52
-
53
- tables = doc.search('table.data-table1')
54
-
55
- tables.each do |table|
56
- # Skip any empty tables. They put these in between post season
57
- # and regular seasons game tables
58
- next if table.children.count <= 1
59
- title = table.search('tr.thd1 td')
60
-
61
- # Need to check for the Regular Season table and a table with no title
62
- # because during the season the NFl splits the games between 2 tables
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
75
- end
76
- end
77
-
78
- schedule
79
- end
80
-
81
- def get_opponent(team, participants)
82
- return nil if participants[0].nil?
83
- p1 = participants[0].inner_text.strip
84
- return participants[1].inner_text.strip if team.short_name == p1
85
- p1
86
- end
87
-
88
- def home_game?(team, participants)
89
- return nil if participants[0].nil?
90
- home_team = participants[1].inner_text.strip
91
- home_team == team.short_name
92
- end
93
- end
94
- 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,79 +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
- end
60
-
61
- def valid_player_hash
62
- {
63
- first_name: 'John',
64
- last_name: 'Elway',
65
- full_name: 'John Elway',
66
- position: 'QB',
67
- number: 7,
68
- status: 'Retired',
69
- team: 'Broncos',
70
- nfl_player_id: '123',
71
- picture_link: 'google.com'
72
- }
73
- end
74
-
75
- it 'can return itself as hash' do
76
- @player.to_hash.must_equal valid_player_hash
77
- end
78
- end
79
- 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