nfl_data 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 20602999e287b633dfc6351d01e33a834a1df252
4
- data.tar.gz: a62ef29bef9b64b1447d6914b433039c6f1fc1a3
3
+ metadata.gz: 9fd1960572c8ad1676477b259f550f616665d587
4
+ data.tar.gz: 23369e62b15791b7885d8b21ab5ab85a9c2cab04
5
5
  SHA512:
6
- metadata.gz: 445d8ac1df6b875dc53097db63ac7c9135e18ea57ad7ce3e16fbe57f70ee295dde7bfb9e61a8ae70eaa08f742f9fab203777d8eec0946025a8e6c66e6a01d228
7
- data.tar.gz: 74164f1e2c0b8e0d8e37cf1c189d6cc19bfc7d79fb6bb2a59b147b043c9375359299f1112b4eed1f02b8c186810f58a01c909ca7356de95286f12a92fcc4d0d6
6
+ metadata.gz: 393b22f179d6c5eb1d7e986d727e634ba647fdd8534bdc6a40f00e9e8ec0a33837f5a795f264d8966e3db74f523c3291ce10e386e09a3215cd18dfbd588ff653
7
+ data.tar.gz: 3473ede86be3f67842d75ba6fe118d70625781e71bb8bd1cf555908722bfe4bc62815fad05466cfdeb30b26e5871a1bc6c97cc402877a79e9b1c1ca3872b4798
data/lib/nfl_data.rb CHANGED
@@ -8,6 +8,7 @@ require 'nfl_data/models/player'
8
8
  require 'nfl_data/models/statline'
9
9
  require 'nfl_data/models/team'
10
10
 
11
+ require 'nfl_data/parsers/parser_helper'
11
12
  require 'nfl_data/parsers/player_parser'
12
13
  require 'nfl_data/parsers/statline_parser'
13
14
  require 'nfl_data/parsers/team_parser'
@@ -22,14 +22,13 @@ module NflData
22
22
  end
23
23
 
24
24
  class Game
25
- attr_accessor :week, :opponent, :date, :time, :home_game
25
+ attr_accessor :week, :opponent, :date, :home_game
26
26
 
27
27
  def to_hash
28
28
  {
29
29
  week: week,
30
30
  opponent: opponent,
31
31
  date: date,
32
- time: time,
33
32
  home_game: home_game
34
33
  }
35
34
  end
@@ -0,0 +1,6 @@
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,5 +1,7 @@
1
1
  module NflData
2
2
  class PlayerParser
3
+ include ParserHelper
4
+
3
5
  attr_reader :base_url
4
6
 
5
7
  def initialize
@@ -65,7 +67,7 @@ module NflData
65
67
  player.number = elements[1].inner_text.strip
66
68
  name = elements[2].inner_text.strip
67
69
  player.status = elements[3].inner_text.strip
68
- player.team = elements[12].inner_text.strip
70
+ player.team = make_jacksonville_abbreviation_consistent(elements[12].inner_text.strip)
69
71
 
70
72
  #Get NFL.com Unique player id
71
73
  player.nfl_player_id = elements[2].to_s.split('/')[3]
@@ -1,5 +1,7 @@
1
1
  module NflData
2
2
  class TeamParser
3
+ include ParserHelper
4
+
3
5
  attr_reader :base_url
4
6
 
5
7
  def initialize
@@ -32,19 +34,13 @@ module NflData
32
34
  team_links.map do |link|
33
35
  team = Team.new
34
36
  team.name = link.inner_text.strip
35
- team.short_name = link.attribute('href').value.scan(/=(.*)/).flatten.first
36
- make_jacksonville_abbreviation_consistent(team)
37
+ team.short_name = make_jacksonville_abbreviation_consistent(link.attribute('href').value.scan(/=(.*)/).flatten.first)
37
38
  team.schedule = get_schedule(team, year) if with_schedule
38
39
 
39
40
  team.to_hash
40
41
  end
41
42
  end
42
43
 
43
- def make_jacksonville_abbreviation_consistent(team)
44
- # Use JAX because schedule pages use JAX and it's easier to fix it here
45
- team.short_name = 'JAX' if team.short_name == 'JAC'
46
- end
47
-
48
44
  def get_schedule(team, year)
49
45
  url = "http://www.nfl.com/teams/schedule?seasonType=REG&team=#{team.short_name}&season=#{year}"
50
46
  schedule = Team::Schedule.new
@@ -54,9 +50,13 @@ module NflData
54
50
  tables = doc.search('table.data-table1')
55
51
 
56
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
57
55
  title = table.search('tr.thd1 td')
58
56
 
59
- if title.inner_text.strip == 'Regular Season'
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
60
  weeks = table.search('tr.tbdy1')
61
61
 
62
62
  weeks.each do |week|
@@ -64,7 +64,6 @@ module NflData
64
64
  elements = week.search('td')
65
65
  game.week = elements[0].inner_text.strip
66
66
  game.date = elements[1].inner_text.strip
67
- game.time = elements[3].nil? ? nil : elements[3].inner_text.strip
68
67
  participants = elements[2].search('a')
69
68
  game.opponent = get_opponent(team, participants)
70
69
  game.home_game = home_game?(team, participants)
@@ -1,3 +1,3 @@
1
1
  module NflData
2
- VERSION = '0.0.9'
2
+ VERSION = '0.0.10'
3
3
  end
@@ -19,7 +19,7 @@ describe PlayerParser do
19
19
  response = @parser.get_by_position(:quarterbacks)
20
20
 
21
21
  response.keys.must_include :quarterbacks
22
- response[:quarterbacks].count.must_equal 121
22
+ response[:quarterbacks].count.must_equal 123
23
23
  end
24
24
  end
25
25
 
@@ -28,7 +28,7 @@ describe PlayerParser do
28
28
  response = @parser.get_by_position(:runningbacks)
29
29
 
30
30
  response.keys.must_include :runningbacks
31
- response[:runningbacks].count.must_equal 231
31
+ response[:runningbacks].count.must_equal 245
32
32
  end
33
33
  end
34
34
 
@@ -37,7 +37,7 @@ describe PlayerParser do
37
37
  response = @parser.get_by_position(:wide_receivers)
38
38
 
39
39
  response.keys.must_include :wide_receivers
40
- response[:wide_receivers].count.must_equal 372
40
+ response[:wide_receivers].count.must_equal 398
41
41
  end
42
42
  end
43
43
 
@@ -46,7 +46,7 @@ describe PlayerParser do
46
46
  response = @parser.get_by_position(:tight_ends)
47
47
 
48
48
  response.keys.must_include :tight_ends
49
- response[:tight_ends].count.must_equal 190
49
+ response[:tight_ends].count.must_equal 206
50
50
  end
51
51
  end
52
52
 
@@ -55,15 +55,26 @@ describe PlayerParser do
55
55
  response = @parser.get_by_position(:all)
56
56
 
57
57
  {
58
- quarterbacks: 121,
59
- runningbacks: 231,
60
- wide_receivers: 372,
61
- tight_ends: 190
58
+ quarterbacks: 123,
59
+ runningbacks: 245,
60
+ wide_receivers: 398,
61
+ tight_ends: 206
62
62
  }.each do |position, player_count|
63
63
  response.keys.must_include position
64
64
  response[position].count.must_equal player_count
65
65
  end
66
66
  end
67
67
  end
68
+
69
+ it 'should use JAX as Jacksonville abbreviation for all JAX team players' do
70
+ VCR.use_cassette('all_players') do
71
+ response = @parser.get_by_position(:all)
72
+
73
+ players = [response[:quarterbacks], response[:runningbacks], response[:wide_receivers], response[:tight_ends]].flatten
74
+
75
+ players.any? {|player| player[:team] == 'JAX'}.must_equal true
76
+ players.none? {|player| player[:team] == 'JAC'}.must_equal true
77
+ end
78
+ end
68
79
  end
69
80
  end
@@ -32,7 +32,9 @@ describe TeamParser do
32
32
 
33
33
  it 'should use JAX as the abbreviation for Jacksonville' do
34
34
  VCR.use_cassette('teams_with_schedule') do
35
- @parser.get_by_year(2014, true).any? {|team| team[:short_name] == 'JAX'}.must_equal true
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
38
  end
37
39
  end
38
40
  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.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - thetizzo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-20 00:00:00.000000000 Z
11
+ date: 2015-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -115,6 +115,7 @@ files:
115
115
  - lib/nfl_data/models/player.rb
116
116
  - lib/nfl_data/models/statline.rb
117
117
  - lib/nfl_data/models/team.rb
118
+ - lib/nfl_data/parsers/parser_helper.rb
118
119
  - lib/nfl_data/parsers/player_parser.rb
119
120
  - lib/nfl_data/parsers/statline_parser.rb
120
121
  - lib/nfl_data/parsers/team_parser.rb