nfl_data 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NjNhOTYxZmI2MDJmNjQ1MzhlOWZkZTY2OGQ1NGZhZTk4MWVjNTRhYQ==
4
+ ZGY4MDZmMWQzZTUxYTNmZDYyYWM0YzlhM2JjNjQxZTYzZGJhOTA1MA==
5
5
  data.tar.gz: !binary |-
6
- ZWJjMzA4YTJiZTcyYWNlZmFlZjQ1YmVlOTJlYmZlM2VhNTM0NWQ5Yg==
6
+ NmM4ZmJlNWEwZmE0ZTQ4YjRkNGYzODg4NmQxYTUyNDcwNWQ4MWY0Zg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MWQ2OWIzNTdjMTEzOWEwNGIxY2RhY2Q1Yjg0YjdmYzNkNjk1YTgwNWQ4M2U0
10
- MmQwMTZjNTkwOGYzMWZkNzBjYjk1YzE4MTM2MDUxYTRlOWQ0NDcyODE5ZDMy
11
- YTBiMDA1YWY0YWY2YmIzZTE5MDNhYjI0NTNjYjVlMDg4NTkwN2U=
9
+ N2MwYWVlZWI2OTQ0M2Y3ZjA5Mjk1OTc4ZmEyNmY5MTk4Y2VlYzZhZjYzZDM4
10
+ ODAyMDhmNzUxYWJiYzFkNGM1YjIzNjc3MjY3NWQ0MDEzOGZiY2MxMGMwMDll
11
+ Y2MwOTQ2MmI1NDc1ZGRiNzZlY2JlYmE3ZDM2Y2I3ODg0MzBjMDY=
12
12
  data.tar.gz: !binary |-
13
- ZTA3ZjhlNDkwNTdlMGJiMDljY2YwMTUwNTQyZTdmNWFhOGI5ZjhlZjZmMzg5
14
- ODJkZGVhNjQ4NmE1NjQ0MThkZTg5MjE5NWJjNTUzNTQ2Y2Q0Y2M4NDdiZDY2
15
- MWE3ODE4ODNhYjRmOTcyM2MzZmNlOGY3NjEzN2Q5ODExMDZhMjc=
13
+ YWQ1MGNhNTc1ODEwODEwZjBkN2U1OGZiMWRjMTQ3Mzk3Mzk5ODE5M2ZlOTZh
14
+ YTk2MDU2MDJhM2ExNTFmZmQ1NTcyOGQwZmE4MjRhNDNlMTA3NTM0NDA0Mjcw
15
+ NTk1Y2M2ODc1OTI2ZmI0OGM0MWJhZWM3M2ZhYmNhN2FmN2NkMGQ=
@@ -2,31 +2,38 @@ module NflData
2
2
  module API
3
3
  class Player
4
4
 
5
+ def initialize
6
+ @parser = PlayerParser.new
7
+ end
8
+
9
+ def get(position)
10
+ @parser.get_by_position(position).to_json
11
+ end
12
+
5
13
  class << self
6
- def positions
7
- ['quarterback', 'runningback', 'widereceiver', 'tightend']
14
+
15
+ def get_all
16
+ self.new.get(:all)
8
17
  end
9
18
 
10
19
  def get_quarterbacks
11
- players = PlayerParser.new.get_by_position('quarterback').map { |player| player.to_json }
12
- JSON.generate({quarterbacks: players})
20
+ self.new.get(:quarterbacks)
13
21
  end
14
22
 
15
23
  def get_runningbacks
16
- players = PlayerParser.new.get_by_position('runningback').map { |player| player.to_json }
17
- JSON.generate({runningbacks: players})
24
+ self.new.get(:runningbacks)
18
25
  end
19
26
 
20
27
  def get_wide_receivers
21
- players = PlayerParser.new.get_by_position('widereceiver').map { |player| player.to_json }
22
- JSON.generate({wide_receivers: players})
28
+ self.new.get(:wide_receivers)
23
29
  end
24
30
 
25
31
  def get_tight_ends
26
- players = PlayerParser.new.get_by_position('tightend').map { |player| player.to_json }
27
- JSON.generate({tight_ends: players})
32
+ self.new.get(:tight_ends)
28
33
  end
34
+
29
35
  end
36
+
30
37
  end
31
38
  end
32
39
  end
@@ -2,13 +2,36 @@ require 'nokogiri'
2
2
 
3
3
  module NflData
4
4
  class PlayerParser
5
+ attr_reader :base_url
5
6
 
6
7
  def initialize
7
- @url = "http://www.nfl.com/players/search?category=position&conferenceAbbr=null&playerType=current&conference=ALL&filter="
8
+ @base_url = "http://www.nfl.com/players/search?category=position&conferenceAbbr=null&playerType=current&conference=ALL&filter="
8
9
  end
9
10
 
10
11
  def get_by_position(position)
11
- baseurl = @url + position
12
+ case position
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
22
+ {
23
+ quarterbacks: get('quarterback'),
24
+ runningbacks: get('runningback'),
25
+ wide_receivers: get('widereceiver'),
26
+ tight_ends: get('tightend')
27
+ }
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def get(position)
34
+ baseurl = @base_url + position
12
35
  url = baseurl
13
36
  returnVal = []
14
37
  page_num = 1
@@ -24,7 +47,7 @@ module NflData
24
47
  url += page_num.to_s
25
48
  end
26
49
 
27
- returnVal.flatten
50
+ returnVal.flatten.map{ |player| player.to_hash }
28
51
  end
29
52
 
30
53
  def update_or_create_players(url)
@@ -45,14 +68,14 @@ module NflData
45
68
  elements = p.search("td")
46
69
  player.position = elements[0].inner_text.strip
47
70
  player.number = elements[1].inner_text.strip
48
- player.name = elements[2].inner_text.strip
71
+ name = elements[2].inner_text.strip
49
72
  player.status = elements[3].inner_text.strip
50
73
  player.team = elements[12].inner_text.strip
51
74
 
52
75
  #Get NFL.com Unique player id
53
76
  player.nfl_player_id = elements[2].to_s.split('/')[3]
54
77
 
55
- names = player.name.split(',')
78
+ names = name.split(',')
56
79
 
57
80
  player.first_name = names[1].strip
58
81
  player.last_name = names[0].strip
@@ -5,8 +5,8 @@ module NflData
5
5
  class Player
6
6
  attr_accessor :first_name, :last_name, :full_name, :position, :number, :status, :team, :nfl_player_id
7
7
 
8
- def to_json
9
- JSON.generate({
8
+ def to_hash
9
+ {
10
10
  first_name: first_name,
11
11
  last_name: last_name,
12
12
  full_name: full_name,
@@ -15,7 +15,7 @@ module NflData
15
15
  status: status,
16
16
  team: team,
17
17
  nfl_player_id: nfl_player_id
18
- })
18
+ }
19
19
  end
20
20
 
21
21
  end
@@ -1,3 +1,3 @@
1
1
  module NflData
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -0,0 +1,15 @@
1
+ require 'test_helper'
2
+
3
+ describe PlayerParser do
4
+ before do
5
+ @parser = PlayerParser.new
6
+ end
7
+
8
+ after do
9
+ @parser = nil
10
+ end
11
+
12
+ it 'should know the correct base url' do
13
+ @parser.base_url.must_equal "http://www.nfl.com/players/search?category=position&conferenceAbbr=null&playerType=current&conference=ALL&filter="
14
+ end
15
+ end
@@ -1,6 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
- describe NflData::Player do
3
+ describe Player do
4
4
  before do
5
5
  @player = NflData::Player.new
6
6
  end
@@ -41,7 +41,7 @@ describe NflData::Player do
41
41
  @player.must_respond_to :nfl_player_id
42
42
  end
43
43
 
44
- describe 'to_json' do
44
+ describe 'to_hash' do
45
45
  before do
46
46
  @player.first_name = 'John'
47
47
  @player.last_name = 'Elway'
@@ -53,8 +53,8 @@ describe NflData::Player do
53
53
  @player.nfl_player_id = '123'
54
54
  end
55
55
 
56
- def valid_player_json
57
- JSON.generate({
56
+ def valid_player_hash
57
+ {
58
58
  first_name: 'John',
59
59
  last_name: 'Elway',
60
60
  full_name: 'John Elway',
@@ -63,11 +63,11 @@ describe NflData::Player do
63
63
  status: 'Retired',
64
64
  team: 'Broncos',
65
65
  nfl_player_id: '123'
66
- })
66
+ }
67
67
  end
68
68
 
69
- it 'can return itself as JSON' do
70
- @player.to_json.must_equal valid_player_json
69
+ it 'can return itself as hash' do
70
+ @player.to_hash.must_equal valid_player_hash
71
71
  end
72
72
 
73
73
  end
data/test/test_helper.rb CHANGED
@@ -2,3 +2,5 @@ require 'nfl_data'
2
2
 
3
3
  require 'minitest/autorun'
4
4
  require 'minitest/pride'
5
+
6
+ include NflData
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.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - thetizzo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-30 00:00:00.000000000 Z
11
+ date: 2014-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -86,6 +86,7 @@ files:
86
86
  - lib/nfl_data/player.rb
87
87
  - lib/nfl_data/version.rb
88
88
  - nfl_data.gemspec
89
+ - test/nfl_data/parsers/player_parser_test.rb
89
90
  - test/nfl_data/player_test.rb
90
91
  - test/test_helper.rb
91
92
  homepage: ''
@@ -113,5 +114,6 @@ signing_key:
113
114
  specification_version: 4
114
115
  summary: Grabber for NFL data that is useful for fantasy purposes from NFL.com
115
116
  test_files:
117
+ - test/nfl_data/parsers/player_parser_test.rb
116
118
  - test/nfl_data/player_test.rb
117
119
  - test/test_helper.rb