nfl_live_update 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ pkg
data/Gemfile.lock CHANGED
@@ -1,15 +1,19 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nfl_live_update (0.0.1)
4
+ nfl_live_update (0.0.2)
5
5
  nokogiri
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
9
9
  specs:
10
+ ansi (1.4.1)
10
11
  coderay (0.9.8)
12
+ metaclass (0.0.1)
11
13
  method_source (0.6.7)
12
14
  ruby_parser (>= 2.3.1)
15
+ mocha (0.10.0)
16
+ metaclass (~> 0.0.1)
13
17
  nokogiri (1.5.0)
14
18
  pry (0.9.7.4)
15
19
  coderay (~> 0.9.8)
@@ -22,13 +26,17 @@ GEM
22
26
  sexp_processor (3.0.10)
23
27
  shoulda (2.11.3)
24
28
  slop (2.1.0)
29
+ turn (0.8.3)
30
+ ansi
25
31
 
26
32
  PLATFORMS
27
33
  ruby
28
34
 
29
35
  DEPENDENCIES
30
36
  bundler
37
+ mocha
31
38
  nfl_live_update!
32
39
  pry
33
40
  rake
34
41
  shoulda
42
+ turn
data/Rakefile CHANGED
@@ -1,16 +1,32 @@
1
1
  require 'bundler'
2
2
  Bundler::GemHelper.install_tasks
3
3
 
4
+ task :default => :test
5
+
4
6
  require 'rake/testtask'
5
7
  Rake::TestTask.new(:test) do |test|
6
8
  test.libs << 'lib' << 'test'
7
- test.test_files = FileList['test/*_test.rb']
9
+ test.test_files = FileList['test/unit/**/*_test.rb', 'test/integration/**/*_test.rb']
8
10
  test.verbose = true
9
11
  # test.warning = true
10
12
  end
11
13
 
12
- task :console do
13
- sh "pry -I lib -r nfl.rb"
14
+ namespace :test do
15
+
16
+ Rake::TestTask.new(:units) do |test|
17
+ test.libs << 'lib' << 'test'
18
+ test.test_files = FileList["test/unit/**/*_test.rb"]
19
+ test.verbose = true
20
+ end
21
+
22
+ Rake::TestTask.new(:integration) do |test|
23
+ test.libs << 'lib' << 'test'
24
+ test.test_files = FileList["test/integration/**/*_test.rb"]
25
+ test.verbose = true
26
+ end
27
+
14
28
  end
15
29
 
16
- task :default => :test
30
+ task :console do
31
+ sh "pry -I lib/nfl -r live_update.rb"
32
+ end
@@ -4,9 +4,9 @@ module NFL
4
4
  class Game
5
5
 
6
6
  attr_accessor :id, :gsis, :day_of_week, :time_of_day, :status,
7
- :home_abbr, :home_nickname, :home_score,
8
- :visitor_abbr, :visitor_nickname, :visitor_score,
9
- :red_zone, :ga, :game_type, :k, :p, :network
7
+ :home_abbr, :home_team_name, :home_nickname, :home_score,
8
+ :visitor_abbr, :visitor_team_name, :visitor_nickname, :visitor_score,
9
+ :red_zone, :ga, :game_type, :k, :p, :network, :o
10
10
 
11
11
  attr_reader :xml
12
12
 
@@ -23,10 +23,12 @@ module NFL
23
23
  @status = attributes["q"]
24
24
 
25
25
  @home_abbr = attributes["h"]
26
+ @home_team_name = attributes["htn"]
26
27
  @home_nickname = attributes["hnn"]
27
28
  @home_score = attributes["hs"]
28
29
 
29
30
  @visitor_abbr = attributes["v"]
31
+ @visitor_team_name = attributes["vtn"]
30
32
  @visitor_nickname = attributes["vnn"]
31
33
  @visitor_score = attributes["vs"]
32
34
 
@@ -37,28 +39,27 @@ module NFL
37
39
  @k = attributes["k"]
38
40
  @p = attributes["p"]
39
41
  @network = attributes["n"]
42
+ @o = attributes["o"]
40
43
  end
41
44
 
42
- end
43
-
44
- private
45
- def set_game_type(gt)
46
- case gt
47
- when "REG"
48
- "Regular"
49
- when "WC"
50
- "Wild Card"
51
- when "CON"
52
- "Conference"
53
- when "DIV"
54
- "Division"
55
- when "PRO"
56
- "Pro Bowl"
57
- else
58
- gt
45
+ def game_type_string
46
+ case @game_type
47
+ when "REG"
48
+ "Regular"
49
+ when "WC"
50
+ "Wild Card"
51
+ when "CON"
52
+ "Conference"
53
+ when "DIV"
54
+ "Division"
55
+ when "PRO"
56
+ "Pro Bowl"
57
+ else
58
+ @game_type
59
+ end
59
60
  end
60
- end
61
61
 
62
+ end
62
63
  end
63
64
  end
64
65
  end
@@ -2,30 +2,56 @@ module NFL
2
2
  module LiveUpdate
3
3
  module ScoreStrip
4
4
  class Games
5
+ private_class_method :new
5
6
 
6
7
  LIVE_UPDATE_URL = "http://www.nfl.com/liveupdate/scorestrip/ss.xml"
8
+ POST_SEASON_URL = "http://www.nfl.com/liveupdate/scorestrip/postseason/ss.xml"
7
9
  AJAX_URL = "http://www.nfl.com/ajax/scorestrip"
8
10
 
11
+ attr_reader :week, :year, :type, :gd, :bph, :games
12
+
9
13
  def initialize(xml)
10
14
  gms = xml.xpath("//ss//gms").first
11
15
 
12
- @week = gms.attribute("w").value
13
- @year = gms.attribute("y").value
14
- @type = gms.attribute("t").value
15
- @gd = gms.attribute("gd").value
16
- @bph = gms.attribute("bph").value
16
+ attributes = gms.attributes
17
+ attributes.each do |k,v|
18
+ attributes[k] = v.text
19
+ end
20
+
21
+ @week = attributes["w"]
22
+ @year = attributes["y"]
23
+ @type = attributes["t"]
24
+ @gd = attributes["gd"]
25
+ @bph = attributes["bph"]
26
+ @bf = attributes["bf"]
27
+
17
28
  @games = gms.xpath("//g").map {|g| Game.new(g) }
18
29
  end
19
30
 
31
+ def type_string
32
+ case @type
33
+ when "R"
34
+ "Regular Season"
35
+ when "POST"
36
+ "Post Season"
37
+ else
38
+ @type
39
+ end
40
+ end
41
+
20
42
  class << self
21
43
 
22
- def current
44
+ def regular_season
23
45
  new(get(LIVE_UPDATE_URL))
24
46
  end
25
47
 
48
+ def post_season
49
+ new(get(POST_SEASON_URL))
50
+ end
51
+
26
52
  def url(params={})
27
- season = params[:season] || Time.now.year
28
- season_type = params[:season_type] || "REG"
53
+ season = params[:season]
54
+ season_type = params[:season_type]
29
55
  week = params[:week]
30
56
  "#{AJAX_URL}?season=#{season}&seasonType=#{season_type}&week=#{week}"
31
57
  end
@@ -1,3 +1,2 @@
1
- require './lib/nfl/live_update/score_strip/base'
2
1
  require './lib/nfl/live_update/score_strip/games'
3
2
  require './lib/nfl/live_update/score_strip/game'
@@ -1,5 +1,5 @@
1
1
  module NFL
2
2
  module LiveUpdate
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -0,0 +1,20 @@
1
+ require 'json'
2
+ require 'nokogiri'
3
+ require 'open-uri'
4
+
5
+ require './lib/nfl/live_update/score_strip'
6
+ require './lib/nfl/live_update/game_center'
7
+
8
+ module NFL
9
+ module LiveUpdate
10
+
11
+ def self.score_strip
12
+ NFL::LiveUpdate::ScoreStrip::Games.regular_season
13
+ end
14
+
15
+ def self.test_game
16
+ NFL::LiveUpdate::GameCenter::Game.test_game
17
+ end
18
+
19
+ end
20
+ end
@@ -19,6 +19,8 @@ Gem::Specification.new do |s|
19
19
  s.add_development_dependency "pry"
20
20
  s.add_development_dependency "bundler"
21
21
  s.add_development_dependency "shoulda"
22
+ s.add_development_dependency "mocha"
23
+ s.add_development_dependency "turn"
22
24
 
23
25
  s.files = `git ls-files`.split("\n")
24
26
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
data/test/test_helper.rb CHANGED
@@ -1,49 +1,6 @@
1
+ require 'rubygems'
1
2
  require 'test/unit'
2
- require 'turn'
3
- require 'active_record'
4
- require 'active_record/fixtures'
5
- require 'yaml'
6
- require 'sqlite3'
7
- require 'enumerated_field'
8
3
  require 'shoulda'
9
- require 'shoulda/active_record'
10
-
11
- ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => ':memory:'
12
- ActiveRecord::Schema.define do
13
- create_table :apples, :force => true do |t|
14
- t.string :color
15
- t.string :kind
16
- end
17
- end
18
-
19
- class Apple < ActiveRecord::Base
20
- include EnumeratedField
21
-
22
- enum_field :color, [['Red', :red], ['Green', :green]], :validate => false
23
- enum_field :kind, [['Fuji Apple', :fuji], ['Delicious Red Apple', :delicious]], :validate => false
24
- end
25
-
26
- class Banana
27
- include EnumeratedField
28
- include ActiveModel::Validations
29
-
30
- attr_accessor :brand
31
- attr_accessor :color
32
- attr_accessor :tastiness
33
-
34
- enum_field :brand, [["Chiquita", :chiquita], ["Del Monte", :delmonte]]
35
- enum_field :color, [["Awesome Yellow", :yellow], ["Icky Green", :green]], :allow_nil => true
36
- # stressing the constantizing of the keys
37
- enum_field :tastiness, [
38
- ["Great", "great!"],
39
- ["Good", "it's good"],
40
- ["Bad", "hate-hate"],
41
- ], :validate => false
42
-
43
- def initialize(brand, color)
44
- self.brand = brand
45
- self.color = color
46
- end
47
- end
48
-
49
- Fixtures.create_fixtures 'test/fixtures', :apples
4
+ require 'turn'
5
+ require 'mocha'
6
+ require 'nfl/live_update'
@@ -0,0 +1,48 @@
1
+ require 'test_helper'
2
+
3
+ module NFL
4
+ module LiveUpdate
5
+ module ScoreStrip
6
+
7
+ class GameTest < Test::Unit::TestCase
8
+
9
+ context "A Game instance" do
10
+ subject do
11
+ games = NFL::LiveUpdate::ScoreStrip::Games.regular_season.games
12
+ games.last
13
+ end
14
+
15
+ should "respond to getter methods" do
16
+ assert_respond_to subject, :id
17
+ assert_respond_to subject, :gsis
18
+ assert_respond_to subject, :day_of_week
19
+ assert_respond_to subject, :time_of_day
20
+ assert_respond_to subject, :status
21
+ assert_respond_to subject, :home_abbr
22
+ assert_respond_to subject, :home_team_name
23
+ assert_respond_to subject, :home_nickname
24
+ assert_respond_to subject, :home_score
25
+ assert_respond_to subject, :visitor_abbr
26
+ assert_respond_to subject, :visitor_team_name
27
+ assert_respond_to subject, :visitor_nickname
28
+ assert_respond_to subject, :visitor_score
29
+ assert_respond_to subject, :red_zone
30
+ assert_respond_to subject, :ga
31
+ assert_respond_to subject, :game_type
32
+ assert_respond_to subject, :k
33
+ assert_respond_to subject, :p
34
+ assert_respond_to subject, :network
35
+ assert_respond_to subject, :o
36
+ end
37
+
38
+ should "have a game_type_string method" do
39
+ assert_equal "Regular", subject.game_type_string
40
+ end
41
+
42
+ end
43
+
44
+ end
45
+
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,69 @@
1
+ require 'test_helper'
2
+
3
+ module NFL
4
+ module LiveUpdate
5
+ module ScoreStrip
6
+
7
+ class GamesTest < Test::Unit::TestCase
8
+
9
+ context "The Games Class" do
10
+ subject { NFL::LiveUpdate::ScoreStrip::Games }
11
+
12
+ setup do
13
+ @live_update_url = NFL::LiveUpdate::ScoreStrip::Games::LIVE_UPDATE_URL
14
+ @post_season_url = NFL::LiveUpdate::ScoreStrip::Games::POST_SEASON_URL
15
+ end
16
+
17
+ should "be able to get the lastest regular season score strip" do
18
+ subject.expects(:get).with(@live_update_url)
19
+ subject.expects(:new)
20
+ subject.regular_season
21
+ end
22
+
23
+ should "be able to get the post season score strip" do
24
+ subject.expects(:get).with(@post_season_url)
25
+ subject.expects(:new)
26
+ subject.post_season
27
+ end
28
+
29
+ should "be able to execute get requests" do
30
+ subject.get(@live_update_url)
31
+ end
32
+
33
+ should "be able to search for old score strips" do
34
+ params = {:week => 1, :season => 2011, :season_type => "REG"}
35
+ subject.expects(:url).with(params)
36
+ subject.expects(:get)
37
+ subject.expects(:new)
38
+ subject.where(params)
39
+ end
40
+
41
+ should "be able to construct urls for retreiving old score strips" do
42
+ subject.url(:week => 1, :season => 2011, :season_type => "REG")
43
+ end
44
+
45
+ end
46
+
47
+ context "A Games instance" do
48
+ subject { NFL::LiveUpdate::ScoreStrip::Games.regular_season }
49
+
50
+ should "respond to getter methods" do
51
+ assert_respond_to subject, :week
52
+ assert_respond_to subject, :year
53
+ assert_respond_to subject, :type
54
+ assert_respond_to subject, :gd
55
+ assert_respond_to subject, :bph
56
+ assert_respond_to subject, :games
57
+ end
58
+
59
+ should "have a type_string method" do
60
+ assert_equal "Regular Season", subject.type_string
61
+ end
62
+
63
+ end
64
+
65
+ end
66
+
67
+ end
68
+ end
69
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nfl_live_update
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-01-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
16
- requirement: &2165580640 !ruby/object:Gem::Requirement
16
+ requirement: &2172816000 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2165580640
24
+ version_requirements: *2172816000
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &2165580220 !ruby/object:Gem::Requirement
27
+ requirement: &2172815320 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2165580220
35
+ version_requirements: *2172815320
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: pry
38
- requirement: &2165579780 !ruby/object:Gem::Requirement
38
+ requirement: &2172814300 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2165579780
46
+ version_requirements: *2172814300
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: bundler
49
- requirement: &2165579320 !ruby/object:Gem::Requirement
49
+ requirement: &2172813340 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *2165579320
57
+ version_requirements: *2172813340
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: shoulda
60
- requirement: &2165578880 !ruby/object:Gem::Requirement
60
+ requirement: &2172812720 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,29 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *2165578880
68
+ version_requirements: *2172812720
69
+ - !ruby/object:Gem::Dependency
70
+ name: mocha
71
+ requirement: &2172811960 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *2172811960
80
+ - !ruby/object:Gem::Dependency
81
+ name: turn
82
+ requirement: &2172811420 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *2172811420
69
91
  description: A Ruby framework for rapid API development with great conventions.
70
92
  email:
71
93
  - ipg49vv2@gmail.com
@@ -73,11 +95,12 @@ executables: []
73
95
  extensions: []
74
96
  extra_rdoc_files: []
75
97
  files:
98
+ - .gitignore
76
99
  - .rvmrc
77
100
  - Gemfile
78
101
  - Gemfile.lock
79
102
  - Rakefile
80
- - lib/nfl.rb
103
+ - lib/nfl/live_update.rb
81
104
  - lib/nfl/live_update/game_center.rb
82
105
  - lib/nfl/live_update/game_center/game.rb
83
106
  - lib/nfl/live_update/game_center/player_stat.rb
@@ -91,7 +114,8 @@ files:
91
114
  - nfl_live_update.gemspec
92
115
  - test/fixtures/apples.yml
93
116
  - test/test_helper.rb
94
- - test/unit/score_strip_games_test.rb
117
+ - test/unit/score_strip/game_test.rb
118
+ - test/unit/score_strip/games_test.rb
95
119
  homepage: https://github.com/jonkarna/nfl_live_update
96
120
  licenses: []
97
121
  post_install_message:
@@ -106,7 +130,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
106
130
  version: '0'
107
131
  segments:
108
132
  - 0
109
- hash: 2352121008628860136
133
+ hash: 364763836256491085
110
134
  required_rubygems_version: !ruby/object:Gem::Requirement
111
135
  none: false
112
136
  requirements:
@@ -115,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
139
  version: '0'
116
140
  segments:
117
141
  - 0
118
- hash: 2352121008628860136
142
+ hash: 364763836256491085
119
143
  requirements: []
120
144
  rubyforge_project: nfl_live_update
121
145
  rubygems_version: 1.8.10
@@ -125,4 +149,5 @@ summary: A simple Ruby framework for building REST-like APIs.
125
149
  test_files:
126
150
  - test/fixtures/apples.yml
127
151
  - test/test_helper.rb
128
- - test/unit/score_strip_games_test.rb
152
+ - test/unit/score_strip/game_test.rb
153
+ - test/unit/score_strip/games_test.rb
data/lib/nfl.rb DELETED
@@ -1,19 +0,0 @@
1
- require 'json'
2
- require 'nokogiri'
3
- require 'open-uri'
4
- require 'rss'
5
-
6
- require './lib/nfl/live_update/score_strip'
7
- require './lib/nfl/live_update/game_center'
8
-
9
- module NFL
10
-
11
- def self.score_strip
12
- NFL::LiveUpdate::ScoreStrip::Games.current
13
- end
14
-
15
- def self.test_game
16
- NFL::LiveUpdate::GameCenter::Game.test_game
17
- end
18
-
19
- end
@@ -1,5 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper'
2
-
3
- class ScoreStripGamesTest < Test::Unit::TestCase
4
-
5
- end