yahoo_sports 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+
2
+ source "https://rubygems.org"
3
+
4
+ gem "tidy"
5
+ gem "scrapi", "~> 1.2.0"
6
+ gem "tzinfo", "~> 0.3.15"
7
+ gem "htmlentities"
8
+
9
+ group :development, :test do
10
+ gem "minitest"
11
+ gem "turn"
12
+ gem "yard"
13
+ gem "jeweler", "~> 1.8.3"
14
+ end
@@ -0,0 +1,36 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ ansi (1.4.3)
5
+ git (1.2.5)
6
+ htmlentities (4.3.1)
7
+ jeweler (1.8.4)
8
+ bundler (~> 1.0)
9
+ git (>= 1.2.5)
10
+ rake
11
+ rdoc
12
+ json (1.7.5)
13
+ minitest (4.0.0)
14
+ rake (0.9.2.2)
15
+ rdoc (3.12)
16
+ json (~> 1.4)
17
+ scrapi (1.2.0)
18
+ tidy (>= 1.1.0)
19
+ tidy (1.1.2)
20
+ turn (0.9.6)
21
+ ansi
22
+ tzinfo (0.3.33)
23
+ yard (0.8.2.1)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ htmlentities
30
+ jeweler (~> 1.8.3)
31
+ minitest
32
+ scrapi (~> 1.2.0)
33
+ tidy
34
+ turn
35
+ tzinfo (~> 0.3.15)
36
+ yard
@@ -4,9 +4,13 @@
4
4
 
5
5
  == DESCRIPTION:
6
6
 
7
- Ruby library for parsing stats from Yahoo! Sports pages. Currently supports
7
+ Ruby library for parsing stats from Yahoo! Sports pages. Currently supports
8
8
  MLB, NBA, NFL and NHL stats and info.
9
9
 
10
+ == DOCUMENTATION:
11
+
12
+ Documentation is available online at at rdoc.info[http://rdoc.info/projects/chetan/yahoo_sports]
13
+
10
14
  == FEATURES:
11
15
 
12
16
  * Pull previous day and current days games for each sport
@@ -29,21 +33,14 @@ MLB, NBA, NFL and NHL stats and info.
29
33
 
30
34
  == INSTALL:
31
35
 
32
- With gemcutter:
33
-
34
36
  sudo gem install yahoo_sports
35
37
 
36
- Without gemcutter:
37
-
38
- git clone git://github.com/chetan/yahoo_sports.git
39
- cd yahoo_sports
40
- sudo rake install
41
38
 
42
39
  == LICENSE:
43
40
 
44
41
  (The MIT License)
45
42
 
46
- Copyright (c) 2009 Pixelcop Resarch, Inc.
43
+ Copyright (c) 2011 Pixelcop Research, Inc.
47
44
 
48
45
  Permission is hereby granted, free of charge, to any person obtaining
49
46
  a copy of this software and associated documentation files (the
@@ -62,4 +59,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
62
59
  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
63
60
  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
64
61
  TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
65
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
62
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile CHANGED
@@ -1,32 +1,37 @@
1
+ # encoding: utf-8
1
2
 
3
+ require 'rubygems'
4
+ require 'bundler'
2
5
  begin
3
- require 'rubygems'
4
- require 'jeweler'
5
- Jeweler::Tasks.new do |gemspec|
6
- gemspec.name = "yahoo_sports"
7
- gemspec.summary = "Ruby library for parsing stats from Yahoo! Sports pages"
8
- gemspec.description = "Ruby library for parsing stats from Yahoo! Sports pages. Currently supports MLB, NBA, NFL and NHL stats and info."
9
- gemspec.email = "chetan@pixelcop.net"
10
- gemspec.homepage = "http://github.com/chetan/yahoo_sports"
11
- gemspec.authors = ["Chetan Sarva"]
12
- gemspec.add_dependency('scrapi', '>= 1.2.0')
13
- gemspec.add_dependency('tzinfo', '>= 0.3.15')
14
- end
15
- Jeweler::GemcutterTasks.new
16
- rescue LoadError
17
- puts "Jeweler not available. Install it with: sudo gem install jeweler"
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
18
11
  end
12
+ require 'rake'
13
+ require 'jeweler'
14
+
15
+ Jeweler::Tasks.new do |gemspec|
16
+ gemspec.name = "yahoo_sports"
17
+ gemspec.summary = "Ruby library for parsing stats from Yahoo! Sports pages"
18
+ gemspec.description = "Ruby library for parsing stats from Yahoo! Sports pages. Currently supports MLB, NBA, NFL and NHL stats and info."
19
+ gemspec.email = "chetan@pixelcop.net"
20
+ gemspec.homepage = "http://github.com/chetan/yahoo_sports"
21
+ gemspec.authors = ["Chetan Sarva"]
22
+ end
23
+ Jeweler::RubygemsDotOrgTasks.new
19
24
 
20
25
  require "rake/testtask"
21
26
  desc "Run unit tests"
22
27
  Rake::TestTask.new("test") { |t|
23
- #t.libs << "test"
24
- t.ruby_opts << "-rubygems"
25
- t.pattern = "test/**/*_test.rb"
28
+ t.libs << 'lib' << 'test'
29
+ t.pattern = "./test/**/*.rb"
26
30
  t.verbose = false
27
31
  t.warning = false
28
32
  }
29
33
 
34
+ task :default => :test
35
+
30
36
  require "yard"
31
- YARD::Rake::YardocTask.new("docs") do |t|
32
- end
37
+ YARD::Rake::YardocTask.new("docs")
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
@@ -5,7 +5,7 @@ require 'tzinfo'
5
5
  if RUBY_PLATFORM =~ /darwin/ then
6
6
  # fix for scrapi on Mac OS X
7
7
  require "tidy"
8
- Tidy.path = "/usr/lib/libtidy.dylib"
8
+ Tidy.path = "/usr/lib/libtidy.dylib"
9
9
  end
10
10
 
11
11
  require 'net/http'
@@ -20,12 +20,12 @@ module YahooSports
20
20
  # @param [String] URL
21
21
  # @return [String] contents of response body
22
22
  def self.fetchurl(url)
23
- #puts "FETCHING #{url}"
24
- return Net::HTTP.get_response(URI.parse(URI.escape(url))).body
23
+ # puts "FETCHING: '#{url}'"
24
+ return Net::HTTP.get_response(URI.parse(URI.escape(url))).body
25
25
  end
26
26
 
27
27
  # Strip HTML tags from the given string. Also performs some common entity
28
- # substitutions.
28
+ # substitutions.
29
29
  #
30
30
  # List of entity codes:
31
31
  # * &nbsp;
@@ -39,7 +39,7 @@ end
39
39
  # @param [String] html text to be filtered
40
40
  # @return [String] original string with HTML tags filtered out and entities replaced
41
41
  def self.strip_tags(html)
42
-
42
+
43
43
  HTMLEntities.new.decode(
44
44
  html.gsub(/<.+?>/,'').
45
45
  gsub(/&nbsp;/,' ').
@@ -60,8 +60,8 @@ class Base
60
60
  # live and upcoming games.
61
61
  #
62
62
  # Source: http://sports.yahoo.com/<sport>
63
- #
64
- # Game struct has the following keys:
63
+ #
64
+ # Game struct has the following keys:
65
65
  # game.date # date of game; includes time if preview
66
66
  # game.team1 # visiting team
67
67
  # game.team2 # home team
@@ -72,7 +72,7 @@ class Base
72
72
  #
73
73
  # Example:
74
74
  # #<OpenStruct state="final", score1="34", date=Thu Nov 26 00:00:00 -0500 2009, score2="12", team1="Green Bay", team2="Detroit">
75
- #
75
+ #
76
76
  #
77
77
  # @param [String] sport sport to list, can be one of ["mlb", "nba", "nfl", "nhl"]
78
78
  # @param [String] state Optionally filter for the given state ("live", "final", or "preview")
@@ -83,54 +83,52 @@ class Base
83
83
  if sport !~ /^(nba|nhl|nfl|mlb)$/ then
84
84
  raise sprintf("Invalid param for 'sport' = '%s'", sport)
85
85
  end
86
-
86
+
87
87
  state.downcase! if not state.empty?
88
88
  if not state.empty? and state !~ /^(live|final|preview)$/ then
89
89
  raise sprintf("Invalid param for 'state' = '%s'", state)
90
90
  end
91
-
92
- html = YahooSports.fetchurl('http://sports.yahoo.com/' + sport)
91
+
92
+ html = YahooSports.fetchurl("http://sports.yahoo.com/#{sport}/proxy/html/scorethin")
93
93
  if not html then
94
94
  raise 'Error fetching url'
95
95
  end
96
96
 
97
97
  sports_game = Scraper.define do
98
-
98
+
99
99
  array :teams
100
100
  array :scores
101
-
101
+
102
102
  process "li.odd, li.even, li.live", :date_src => "@id"
103
103
  process "li.odd, li.even, li.live", :class_src => "@class"
104
104
  process "li.link-box", :extra_src => :text
105
-
105
+
106
106
  process "td.team>a", :teams => :text
107
107
  process "td.score", :scores => :text
108
-
108
+
109
109
  process "li.status>a", :status => :text
110
-
111
-
110
+
111
+
112
112
  result :date_src, :teams, :scores, :status, :class_src, :extra_src
113
-
113
+
114
114
  end
115
-
115
+
116
116
  sports = Scraper.define do
117
-
117
+
118
118
  array :games
119
-
119
+
120
120
  process "ul.game-list>li", :games => sports_game
121
-
121
+
122
122
  result :games
123
-
123
+
124
124
  end
125
-
126
- games_temp = sports.scrape(html)
127
125
 
126
+ games_temp = sports.scrape(html)
128
127
  games = []
129
-
130
128
  return games if games_temp.nil?
131
-
129
+
132
130
  games_temp.each { |g|
133
-
131
+
134
132
  gm = OpenStruct.new
135
133
  gm.team1 = g.teams[0].strip if g.teams[0]
136
134
  gm.team2 = g.teams[1].strip if g.teams[1]
@@ -142,27 +140,27 @@ class Base
142
140
  else
143
141
  gm.state = g.class_src.strip
144
142
  end
145
-
143
+
146
144
  gm.tv = $1 if g.extra_src =~ /TV: (.*)/
147
145
 
148
146
  status = g.status.strip if g.status
149
147
  time_str = (gm.state == "preview" ? " #{status}" : "")
150
-
148
+
151
149
  if sport == 'mlb' then
152
150
  gm.date = Time.parse(Time.new.strftime('%Y') + g.date_src[2,4] + time_str)
153
151
  else
154
152
  gm.date = Time.parse(g.date_src[0,8] + time_str)
155
153
  end
156
-
154
+
157
155
  next if not state.empty? and state != gm.state
158
156
  games << gm
159
-
157
+
160
158
  }
161
-
159
+
162
160
  return games
163
-
161
+
164
162
  end
165
-
163
+
166
164
  # Retrieves team information for the team in the given sport
167
165
  #
168
166
  # Source: http://sports.yahoo.com/<sport>/teams/<team>
@@ -186,7 +184,7 @@ class Base
186
184
  # @param [String] str 3-letter team code or partial team name
187
185
  # @return [OpenStruct] team info
188
186
  def self.get_team_stats(sport, str)
189
-
187
+
190
188
  sport.downcase!
191
189
  if sport !~ /^(nba|nhl|nfl|mlb)$/ then
192
190
  raise sprintf("Invalid param for 'sport' = '%s'", sport)
@@ -197,11 +195,11 @@ class Base
197
195
  if html.nil? then
198
196
  raise sprintf("Can't find team '%s'", str)
199
197
  end
200
-
198
+
201
199
  info = get_team_info(html)
202
200
  last5, next5 = get_scores_and_schedule(html)
203
201
  live_game = get_live_game(info.name, html)
204
-
202
+
205
203
  return OpenStruct.new({:name => info.name,
206
204
  :standing => info.standing,
207
205
  :position => info.position,
@@ -209,59 +207,59 @@ class Base
209
207
  :next5 => next5,
210
208
  :live => live_game})
211
209
  end
212
-
213
-
210
+
211
+
214
212
  private
215
-
213
+
216
214
  def self.get_team_info(html)
217
-
215
+
218
216
  info_scraper = Scraper.define do
219
-
217
+
220
218
  process "div#team-header div.info h1", :name => :text
221
219
  process "div#team-header div.info div.stats li.score", :standing => :text
222
220
  process "div#team-header div.info div.stats li.position", :position => :text
223
-
221
+
224
222
  result :name, :standing, :position
225
223
  end
226
-
224
+
227
225
  info_temp = info_scraper.scrape(html)
228
-
226
+
229
227
  info = OpenStruct.new
230
228
  return info if info_temp.nil?
231
-
229
+
232
230
  info.name = info_temp.name
233
231
  info_temp.standing.gsub!(/,/, '')
234
232
  info.standing = info_temp.standing
235
- info.position = info_temp.position
236
- return info
233
+ info.position = info_temp.position
234
+ return info
237
235
  end
238
-
236
+
239
237
  def self.get_scores_and_schedule(html)
240
238
 
241
239
  last5 = []
242
240
  next5 = []
243
-
241
+
244
242
  games_scraper = Scraper.define do
245
-
243
+
246
244
  array :games
247
245
  array :teams
248
-
246
+
249
247
  process "div#team-schedule-list div.bd table tbody tr", :games => :text
250
248
  process "div#team-schedule-list div.bd table tbody tr td.title span", :teams => :text
251
-
249
+
252
250
  result :games, :teams
253
-
251
+
254
252
  end
255
-
253
+
256
254
  games_temp = games_scraper.scrape(html)
257
-
255
+
258
256
  return [last5, next5] if games_temp.nil?
259
-
257
+
260
258
  bye = false # bye week support for nfl
261
259
  bye_added = false # help us put it in the right place (hopefully)
262
-
260
+
263
261
  games_temp.games.each_index { |i|
264
-
262
+
265
263
  info = games_temp.games[i].split("\n").slice(1, 3)
266
264
  if info[0] == "Bye"
267
265
  # team is in a bye week
@@ -271,22 +269,22 @@ class Base
271
269
  t = (bye ? i - 1 : i)
272
270
  team = games_temp.teams[t].strip
273
271
  end
274
-
272
+
275
273
  gm = OpenStruct.new
276
-
274
+
277
275
  info[1] =~ /(\([\d-]+\))/
278
276
  record = $1
279
277
  status = info[2]
280
-
278
+
281
279
  preview = (status !~ /^(W|L)/)
282
280
  date_str = (preview ? "#{info[0]} #{status}" : info[0])
283
- gm.date = Time.parse(date_str)
284
-
281
+ gm.date = Time.parse(date_str)
282
+
285
283
  gm.team = "#{team} #{record}".strip
286
284
  gm.status = (preview ? "preview" : status)
287
285
 
288
286
  gm.away = (info[1] =~ / at / ? true : false)
289
-
287
+
290
288
  if preview then
291
289
  if bye and not bye_added then
292
290
  gmb = OpenStruct.new
@@ -294,7 +292,7 @@ class Base
294
292
  next5 << gmb
295
293
  bye_added = true
296
294
  end
297
- next5 << gm
295
+ next5 << gm
298
296
  else
299
297
  if bye and not bye_added then
300
298
  gmb = OpenStruct.new
@@ -304,78 +302,78 @@ class Base
304
302
  end
305
303
  last5 << gm
306
304
  end
307
-
305
+
308
306
  }
309
-
307
+
310
308
  return [last5, next5]
311
309
  end
312
-
310
+
313
311
  def self.get_live_game(team, html)
314
-
312
+
315
313
  return nil if html !~ /In Progress Game/
316
-
314
+
317
315
  team_scraper = Scraper.define do
318
-
316
+
319
317
  process_first "td:nth-child(2)", :name => :text
320
318
  process_first "td:nth-child(4)", :runs => :text
321
319
  process_first "td:nth-child(5)", :hits => :text
322
320
  process_first "td:nth-child(6)", :errors => :text
323
-
321
+
324
322
  result :name, :runs, :hits, :errors
325
-
323
+
326
324
  end
327
-
325
+
328
326
  live_scraper = Scraper.define do
329
327
  array :teams
330
328
  process_first "td.yspscores", :inning => :text
331
329
  process "tr.ysptblclbg5", :teams => team_scraper
332
330
  result :inning, :teams
333
331
  end
334
-
332
+
335
333
  game = live_scraper.scrape(html)
336
334
  game = struct_to_ostruct(game)
337
335
  game.inning.strip!
338
-
336
+
339
337
  # they are at home if team 1 (2nd team) is them
340
338
  if game.teams[1].name.split.size > 1 then
341
339
  t = game.teams[1].name.split[-1]
342
340
  else
343
341
  t = game.teams[1].name
344
342
  end
345
-
343
+
346
344
  if team.include? t then
347
345
  # home game
348
346
  game.home = true
349
347
  else
350
- game.home = false
348
+ game.home = false
351
349
  end
352
350
 
353
- # helpers
351
+ # helpers
354
352
  game.away_team = game.teams[0]
355
353
  game.home_team = game.teams[1]
356
354
  game.delete_field('teams')
357
-
355
+
358
356
  return game
359
-
357
+
360
358
  end
361
-
359
+
362
360
  def self.find_team_page(sport, str)
363
-
361
+
364
362
  sport.downcase!
365
- str.downcase!
366
-
363
+ str.downcase!
364
+
367
365
  begin
368
366
  html = YahooSports.fetchurl("http://sports.yahoo.com/#{sport}/teams/" + str)
369
367
  rescue => ex
370
368
  puts ex
371
369
  return
372
370
  end
373
-
371
+
374
372
  if html !~ %r{<title><MapleRegion id ="page_title_generic"/></title>} then
375
373
  # got the right page
376
374
  return [str, html]
377
375
  end
378
-
376
+
379
377
  # look for it
380
378
  begin
381
379
  html = YahooSports.fetchurl("http://sports.yahoo.com/#{sport}/teams")
@@ -393,15 +391,15 @@ class Base
393
391
  process "table.yspcontent tr.ysprow2 a", :links => "@href"
394
392
  result :teams, :links
395
393
  end
396
-
394
+
397
395
  ret = team_scraper.scrape(html)
398
396
  return nil if ret.nil?
399
-
397
+
400
398
  ret.teams.each_index { |i|
401
399
  t = ret.teams[i]
402
400
  l = ret.links[i].strip.gsub(%r{/$}, "") # strip trailing slash for nfl
403
401
  t = YahooSports.strip_tags(t).strip
404
-
402
+
405
403
  if t == str or t.downcase.include? str then
406
404
  # found a matching team
407
405
  begin
@@ -414,11 +412,11 @@ class Base
414
412
  return [$1, html]
415
413
  end
416
414
  }
417
-
415
+
418
416
  return nil
419
-
417
+
420
418
  end
421
-
419
+
422
420
  def self.struct_to_ostruct(struct)
423
421
  hash = {}
424
422
  struct.each_pair { |key,val|
@@ -1,12 +1,105 @@
1
+
2
+ require 'rubygems'
1
3
  require 'stringio'
2
- require 'test/unit'
3
4
  require File.dirname(__FILE__) + '/../lib/yahoo_sports'
4
5
 
5
- begin; require "turn"; rescue LoadError; end
6
-
6
+ # if RUBY_PLATFORM =~ /darwin/ and `which tidy` !~ %r{/opt/local} then
7
7
  if RUBY_PLATFORM =~ /darwin/ then
8
8
  # fix for scrapi on Mac OS X
9
- require "rubygems"
10
9
  require "tidy"
11
- Tidy.path = "/usr/lib/libtidy.dylib"
12
- end
10
+ Tidy.path = "/usr/lib/libtidy.dylib"
11
+ end
12
+
13
+ require 'bundler'
14
+ begin
15
+ Bundler.setup(:default, :development)
16
+ rescue Bundler::BundlerError => e
17
+ $stderr.puts e.message
18
+ $stderr.puts "Run `bundle install` to install missing gems"
19
+ exit e.status_code
20
+ end
21
+
22
+ module Rake
23
+ class << self
24
+ def verbose?
25
+ ENV.include? "VERBOSE" and ["1", "true", "yes"].include? ENV["VERBOSE"]
26
+ end
27
+ end
28
+ end
29
+
30
+ require 'minitest/unit'
31
+ require 'turn'
32
+ require 'turn/reporter'
33
+ require 'turn/reporters/outline_reporter'
34
+
35
+ Turn.config.framework = :minitest
36
+ Turn.config.format = :outline
37
+ Turn.config.natural = true
38
+
39
+ module Turn
40
+ class OutlineReporter < Reporter
41
+ def start_test(test)
42
+
43
+ @last_test = test
44
+
45
+ # create new captures for each test (so we don't get repeated messages)
46
+ @stdout = StringIO.new
47
+ @stderr = StringIO.new
48
+
49
+ name = naturalized_name(test)
50
+
51
+ io.print " %-57s" % name
52
+
53
+ @stdout.rewind
54
+ @stderr.rewind
55
+
56
+ $stdout = @stdout
57
+ $stderr = @stderr unless $DEBUG
58
+
59
+ @clean = false
60
+ at_exit do
61
+ if not @clean then
62
+ puts "program quit unexpectedly!"
63
+ show_captured_output()
64
+ end
65
+ end
66
+ end
67
+
68
+ def finish_test(test)
69
+ super
70
+ @clean = true
71
+ end
72
+
73
+ # override so we can dump stdout/stderr even if the test passes
74
+ def pass(message=nil)
75
+ io.puts " %s %s" % [ticktock, PASS]
76
+
77
+ if message
78
+ message = Colorize.magenta(message)
79
+ message = message.to_s.tabto(TAB_SIZE)
80
+ io.puts(message)
81
+ end
82
+
83
+ @clean = true
84
+ show_captured_output if Rake.verbose?
85
+ end
86
+
87
+ # override to add test name to output
88
+ def show_captured_stdout
89
+ @clean = true
90
+ @stdout.rewind
91
+ return if @stdout.eof?
92
+ STDOUT.puts(<<-output.tabto(8))
93
+ \n\nSTDOUT (#{naturalized_name(@last_test)}):
94
+ -------------------------------------------------------------------------------
95
+
96
+ #{@stdout.read}
97
+ output
98
+ end
99
+ end
100
+ end
101
+
102
+ Turn.config.framework = :minitest
103
+ Turn.config.format = :outline
104
+
105
+ MiniTest::Unit.autorun
@@ -1,14 +1,14 @@
1
1
  require File.dirname(__FILE__) + '/test_helper.rb'
2
2
 
3
- class YahooSports_Test < Test::Unit::TestCase
4
-
3
+ class YahooSports_Test < MiniTest::Unit::TestCase
4
+
5
5
  def test_autoload_classes
6
-
6
+
7
7
  assert YahooSports::MLB
8
8
  assert YahooSports::NBA
9
9
  assert YahooSports::NFL
10
10
  assert YahooSports::NHL
11
-
11
+
12
12
  end
13
-
13
+
14
14
  end
@@ -1,9 +1,9 @@
1
1
  require File.dirname(__FILE__) + '/../test_helper.rb'
2
2
 
3
- class YahooSports_Test < Test::Unit::TestCase
4
-
3
+ class YahooSports_Test < MiniTest::Unit::TestCase
4
+
5
5
  def test_get_homepage_games_sport_check
6
-
6
+
7
7
  begin
8
8
  YahooSports::Base.get_homepage_games("MLB")
9
9
  rescue RuntimeError => e
@@ -11,7 +11,7 @@ class YahooSports_Test < Test::Unit::TestCase
11
11
  flunk("no exception should have been raised")
12
12
  end
13
13
  end
14
-
14
+
15
15
  end
16
-
16
+
17
17
  end
@@ -1,30 +1,32 @@
1
1
  require File.dirname(__FILE__) + '/../test_helper.rb'
2
2
 
3
- class MLB_Test < Test::Unit::TestCase
4
-
5
- def test_get_homepage_games
6
- YahooSports::MLB.get_homepage_games
3
+ class MLB_Test < MiniTest::Unit::TestCase
4
+
5
+ def test_get_homepage_games
6
+ games = YahooSports::MLB.get_homepage_games
7
+ assert games
8
+ refute_empty games
7
9
  end
8
-
10
+
9
11
  def test_get_team_stats
10
- run_test("NYY")
12
+ run_tests("NYY")
11
13
  end
12
-
14
+
13
15
  def test_get_team_stats_by_name
14
- run_test("yankees")
16
+ run_tests("yankees")
15
17
  end
16
-
18
+
17
19
  private
18
-
19
- def run_test(str)
20
+
21
+ def run_tests(str)
20
22
  team = YahooSports::MLB.get_team_stats(str)
21
23
  assert(team.name)
22
24
  assert_equal("New York Yankees", team.name)
23
25
  assert(team.standing)
24
26
  assert(team.standing =~ /^\d+\-\d+$/)
25
27
  assert(team.position)
26
- assert((not team.last5.empty?), "last 5 games")
28
+ assert((not (team.last5.empty? and team.next5.empty?)), "last 5 and next 5 games")
27
29
  assert(team.next5)
28
30
  end
29
-
31
+
30
32
  end
@@ -1,30 +1,32 @@
1
1
  require File.dirname(__FILE__) + '/../test_helper.rb'
2
2
 
3
- class NBA_Test < Test::Unit::TestCase
4
-
5
- def test_get_homepage_games
6
- YahooSports::NBA.get_homepage_games
3
+ class NBA_Test < MiniTest::Unit::TestCase
4
+
5
+ def test_get_homepage_games
6
+ games = YahooSports::NBA.get_homepage_games
7
+ assert games
8
+ refute_empty games
7
9
  end
8
-
10
+
9
11
  def test_get_team_stats
10
- run_test("NYK")
12
+ run_tests("NYK")
11
13
  end
12
-
14
+
13
15
  def test_get_team_stats_by_name
14
- run_test("knicks")
16
+ run_tests("knicks")
15
17
  end
16
-
18
+
17
19
  private
18
-
19
- def run_test(str)
20
+
21
+ def run_tests(str)
20
22
  team = YahooSports::NBA.get_team_stats(str)
21
23
  assert(team.name)
22
24
  assert_equal("New York Knicks", team.name)
23
25
  assert(team.standing)
24
26
  assert(team.standing =~ /^\d+\-\d+$/)
25
27
  assert(team.position)
26
- assert((not team.last5.empty?), "last 5 games")
28
+ assert((not (team.last5.empty? and team.next5.empty?)), "last 5 and next 5 games")
27
29
  assert(team.next5)
28
30
  end
29
-
31
+
30
32
  end
@@ -1,30 +1,32 @@
1
1
  require File.dirname(__FILE__) + '/../test_helper.rb'
2
2
 
3
- class NFL_Test < Test::Unit::TestCase
4
-
5
- def test_get_homepage_games
6
- YahooSports::NFL.get_homepage_games
3
+ class NFL_Test < MiniTest::Unit::TestCase
4
+
5
+ def test_get_homepage_games
6
+ games = YahooSports::NFL.get_homepage_games
7
+ assert games
8
+ refute_empty games
7
9
  end
8
-
10
+
9
11
  def test_get_team_stats
10
- run_test("NYJ")
12
+ run_tests("NYJ")
11
13
  end
12
-
14
+
13
15
  def test_get_team_stats_by_name
14
- run_test("jets")
16
+ run_tests("jets")
15
17
  end
16
-
18
+
17
19
  private
18
-
19
- def run_test(str)
20
+
21
+ def run_tests(str)
20
22
  team = YahooSports::NFL.get_team_stats(str)
21
23
  assert(team.name)
22
24
  assert_equal("New York Jets", team.name)
23
25
  assert(team.standing)
24
26
  assert(team.standing =~ /^\d+\-\d+(-\d+)?$/)
25
27
  assert(team.position)
26
- assert((not team.last5.empty?), "last 5 games")
28
+ assert((not (team.last5.empty? and team.next5.empty?)), "last 5 and next 5 games")
27
29
  assert(team.next5)
28
30
  end
29
-
31
+
30
32
  end
@@ -1,30 +1,32 @@
1
1
  require File.dirname(__FILE__) + '/../test_helper.rb'
2
2
 
3
- class NHL_Test < Test::Unit::TestCase
4
-
5
- def test_get_homepage_games
6
- YahooSports::NHL.get_homepage_games
3
+ class NHL_Test < MiniTest::Unit::TestCase
4
+
5
+ def test_get_homepage_games
6
+ games = YahooSports::NHL.get_homepage_games
7
+ assert games
8
+ refute_empty games
7
9
  end
8
-
10
+
9
11
  def test_get_team_stats
10
- run_test("NYR")
12
+ run_tests("NYR")
11
13
  end
12
-
14
+
13
15
  def test_get_team_stats_by_name
14
- run_test("rangers")
16
+ run_tests("rangers")
15
17
  end
16
-
18
+
17
19
  private
18
-
19
- def run_test(str)
20
+
21
+ def run_tests(str)
20
22
  team = YahooSports::NHL.get_team_stats(str)
21
23
  assert(team.name)
22
24
  assert_equal("New York Rangers", team.name)
23
25
  assert(team.standing)
24
26
  assert(team.standing =~ /^\d+\-\d+(-\d+)?$/)
25
27
  assert(team.position)
26
- assert((not team.last5.empty?), "last 5 games")
28
+ assert((not (team.last5.empty? and team.next5.empty?)), "last 5 and next 5 games")
27
29
  assert(team.next5)
28
30
  end
29
-
31
+
30
32
  end
@@ -1,70 +1,79 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{yahoo_sports}
8
- s.version = "0.2.0"
7
+ s.name = "yahoo_sports"
8
+ s.version = "0.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Chetan Sarva"]
12
- s.date = %q{2009-11-30}
13
- s.description = %q{Ruby library for parsing stats from Yahoo! Sports pages. Currently supports MLB, NBA, NFL and NHL stats and info.}
14
- s.email = %q{chetan@pixelcop.net}
12
+ s.date = "2012-10-05"
13
+ s.description = "Ruby library for parsing stats from Yahoo! Sports pages. Currently supports MLB, NBA, NFL and NHL stats and info."
14
+ s.email = "chetan@pixelcop.net"
15
15
  s.extra_rdoc_files = [
16
16
  "README.rdoc"
17
17
  ]
18
18
  s.files = [
19
+ "Gemfile",
20
+ "Gemfile.lock",
19
21
  "History.txt",
20
- "Manifest.txt",
21
- "README.rdoc",
22
- "Rakefile",
23
- "VERSION",
24
- "lib/yahoo_sports.rb",
25
- "lib/yahoo_sports/base.rb",
26
- "lib/yahoo_sports/mlb.rb",
27
- "lib/yahoo_sports/nba.rb",
28
- "lib/yahoo_sports/nfl.rb",
29
- "lib/yahoo_sports/nhl.rb",
30
- "test/test_helper.rb",
31
- "test/yahoo_sports/base_test.rb",
32
- "test/yahoo_sports/mlb_test.rb",
33
- "test/yahoo_sports/nba_test.rb",
34
- "test/yahoo_sports/nfl_test.rb",
35
- "test/yahoo_sports/nhl_test.rb",
36
- "test/yahoo_sports_test.rb",
37
- "yahoo_sports.gemspec"
38
- ]
39
- s.homepage = %q{http://github.com/chetan/yahoo_sports}
40
- s.rdoc_options = ["--charset=UTF-8"]
41
- s.require_paths = ["lib"]
42
- s.rubygems_version = %q{1.3.5}
43
- s.summary = %q{Ruby library for parsing stats from Yahoo! Sports pages}
44
- s.test_files = [
22
+ "Manifest.txt",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/yahoo_sports.rb",
27
+ "lib/yahoo_sports/base.rb",
28
+ "lib/yahoo_sports/mlb.rb",
29
+ "lib/yahoo_sports/nba.rb",
30
+ "lib/yahoo_sports/nfl.rb",
31
+ "lib/yahoo_sports/nhl.rb",
45
32
  "test/test_helper.rb",
46
- "test/yahoo_sports/base_test.rb",
47
- "test/yahoo_sports/mlb_test.rb",
48
- "test/yahoo_sports/nba_test.rb",
49
- "test/yahoo_sports/nfl_test.rb",
50
- "test/yahoo_sports/nhl_test.rb",
51
- "test/yahoo_sports_test.rb"
33
+ "test/test_yahoo_sports.rb",
34
+ "test/yahoo_sports/test_base.rb",
35
+ "test/yahoo_sports/test_mlb.rb",
36
+ "test/yahoo_sports/test_nba.rb",
37
+ "test/yahoo_sports/test_nfl.rb",
38
+ "test/yahoo_sports/test_nhl.rb",
39
+ "yahoo_sports.gemspec"
52
40
  ]
41
+ s.homepage = "http://github.com/chetan/yahoo_sports"
42
+ s.require_paths = ["lib"]
43
+ s.rubygems_version = "1.8.24"
44
+ s.summary = "Ruby library for parsing stats from Yahoo! Sports pages"
53
45
 
54
46
  if s.respond_to? :specification_version then
55
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
56
47
  s.specification_version = 3
57
48
 
58
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
59
- s.add_runtime_dependency(%q<scrapi>, [">= 1.2.0"])
60
- s.add_runtime_dependency(%q<tzinfo>, [">= 0.3.15"])
49
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
50
+ s.add_runtime_dependency(%q<tidy>, [">= 0"])
51
+ s.add_runtime_dependency(%q<scrapi>, ["~> 1.2.0"])
52
+ s.add_runtime_dependency(%q<tzinfo>, ["~> 0.3.15"])
53
+ s.add_runtime_dependency(%q<htmlentities>, [">= 0"])
54
+ s.add_development_dependency(%q<minitest>, [">= 0"])
55
+ s.add_development_dependency(%q<turn>, [">= 0"])
56
+ s.add_development_dependency(%q<yard>, [">= 0"])
57
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
61
58
  else
62
- s.add_dependency(%q<scrapi>, [">= 1.2.0"])
63
- s.add_dependency(%q<tzinfo>, [">= 0.3.15"])
59
+ s.add_dependency(%q<tidy>, [">= 0"])
60
+ s.add_dependency(%q<scrapi>, ["~> 1.2.0"])
61
+ s.add_dependency(%q<tzinfo>, ["~> 0.3.15"])
62
+ s.add_dependency(%q<htmlentities>, [">= 0"])
63
+ s.add_dependency(%q<minitest>, [">= 0"])
64
+ s.add_dependency(%q<turn>, [">= 0"])
65
+ s.add_dependency(%q<yard>, [">= 0"])
66
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
64
67
  end
65
68
  else
66
- s.add_dependency(%q<scrapi>, [">= 1.2.0"])
67
- s.add_dependency(%q<tzinfo>, [">= 0.3.15"])
69
+ s.add_dependency(%q<tidy>, [">= 0"])
70
+ s.add_dependency(%q<scrapi>, ["~> 1.2.0"])
71
+ s.add_dependency(%q<tzinfo>, ["~> 0.3.15"])
72
+ s.add_dependency(%q<htmlentities>, [">= 0"])
73
+ s.add_dependency(%q<minitest>, [">= 0"])
74
+ s.add_dependency(%q<turn>, [">= 0"])
75
+ s.add_dependency(%q<yard>, [">= 0"])
76
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
68
77
  end
69
78
  end
70
79
 
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yahoo_sports
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ hash: 21
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 2
9
+ - 1
10
+ version: 0.2.1
5
11
  platform: ruby
6
12
  authors:
7
13
  - Chetan Sarva
@@ -9,29 +15,126 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2009-11-30 00:00:00 -05:00
13
- default_executable:
18
+ date: 2012-10-05 00:00:00 Z
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
- name: scrapi
17
21
  type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
20
24
  requirements:
21
25
  - - ">="
22
26
  - !ruby/object:Gem::Version
27
+ hash: 3
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ version_requirements: *id001
32
+ name: tidy
33
+ prerelease: false
34
+ - !ruby/object:Gem::Dependency
35
+ type: :runtime
36
+ requirement: &id002 !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ hash: 31
42
+ segments:
43
+ - 1
44
+ - 2
45
+ - 0
23
46
  version: 1.2.0
24
- version:
47
+ version_requirements: *id002
48
+ name: scrapi
49
+ prerelease: false
25
50
  - !ruby/object:Gem::Dependency
51
+ type: :runtime
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ~>
56
+ - !ruby/object:Gem::Version
57
+ hash: 13
58
+ segments:
59
+ - 0
60
+ - 3
61
+ - 15
62
+ version: 0.3.15
63
+ version_requirements: *id003
26
64
  name: tzinfo
65
+ prerelease: false
66
+ - !ruby/object:Gem::Dependency
27
67
  type: :runtime
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
68
+ requirement: &id004 !ruby/object:Gem::Requirement
69
+ none: false
30
70
  requirements:
31
71
  - - ">="
32
72
  - !ruby/object:Gem::Version
33
- version: 0.3.15
34
- version:
73
+ hash: 3
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ version_requirements: *id004
78
+ name: htmlentities
79
+ prerelease: false
80
+ - !ruby/object:Gem::Dependency
81
+ type: :development
82
+ requirement: &id005 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ hash: 3
88
+ segments:
89
+ - 0
90
+ version: "0"
91
+ version_requirements: *id005
92
+ name: minitest
93
+ prerelease: false
94
+ - !ruby/object:Gem::Dependency
95
+ type: :development
96
+ requirement: &id006 !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ hash: 3
102
+ segments:
103
+ - 0
104
+ version: "0"
105
+ version_requirements: *id006
106
+ name: turn
107
+ prerelease: false
108
+ - !ruby/object:Gem::Dependency
109
+ type: :development
110
+ requirement: &id007 !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ hash: 3
116
+ segments:
117
+ - 0
118
+ version: "0"
119
+ version_requirements: *id007
120
+ name: yard
121
+ prerelease: false
122
+ - !ruby/object:Gem::Dependency
123
+ type: :development
124
+ requirement: &id008 !ruby/object:Gem::Requirement
125
+ none: false
126
+ requirements:
127
+ - - ~>
128
+ - !ruby/object:Gem::Version
129
+ hash: 49
130
+ segments:
131
+ - 1
132
+ - 8
133
+ - 3
134
+ version: 1.8.3
135
+ version_requirements: *id008
136
+ name: jeweler
137
+ prerelease: false
35
138
  description: Ruby library for parsing stats from Yahoo! Sports pages. Currently supports MLB, NBA, NFL and NHL stats and info.
36
139
  email: chetan@pixelcop.net
37
140
  executables: []
@@ -41,6 +144,8 @@ extensions: []
41
144
  extra_rdoc_files:
42
145
  - README.rdoc
43
146
  files:
147
+ - Gemfile
148
+ - Gemfile.lock
44
149
  - History.txt
45
150
  - Manifest.txt
46
151
  - README.rdoc
@@ -53,46 +158,45 @@ files:
53
158
  - lib/yahoo_sports/nfl.rb
54
159
  - lib/yahoo_sports/nhl.rb
55
160
  - test/test_helper.rb
56
- - test/yahoo_sports/base_test.rb
57
- - test/yahoo_sports/mlb_test.rb
58
- - test/yahoo_sports/nba_test.rb
59
- - test/yahoo_sports/nfl_test.rb
60
- - test/yahoo_sports/nhl_test.rb
61
- - test/yahoo_sports_test.rb
161
+ - test/test_yahoo_sports.rb
162
+ - test/yahoo_sports/test_base.rb
163
+ - test/yahoo_sports/test_mlb.rb
164
+ - test/yahoo_sports/test_nba.rb
165
+ - test/yahoo_sports/test_nfl.rb
166
+ - test/yahoo_sports/test_nhl.rb
62
167
  - yahoo_sports.gemspec
63
- has_rdoc: true
64
168
  homepage: http://github.com/chetan/yahoo_sports
65
169
  licenses: []
66
170
 
67
171
  post_install_message:
68
- rdoc_options:
69
- - --charset=UTF-8
172
+ rdoc_options: []
173
+
70
174
  require_paths:
71
175
  - lib
72
176
  required_ruby_version: !ruby/object:Gem::Requirement
177
+ none: false
73
178
  requirements:
74
179
  - - ">="
75
180
  - !ruby/object:Gem::Version
181
+ hash: 3
182
+ segments:
183
+ - 0
76
184
  version: "0"
77
- version:
78
185
  required_rubygems_version: !ruby/object:Gem::Requirement
186
+ none: false
79
187
  requirements:
80
188
  - - ">="
81
189
  - !ruby/object:Gem::Version
190
+ hash: 3
191
+ segments:
192
+ - 0
82
193
  version: "0"
83
- version:
84
194
  requirements: []
85
195
 
86
196
  rubyforge_project:
87
- rubygems_version: 1.3.5
197
+ rubygems_version: 1.8.24
88
198
  signing_key:
89
199
  specification_version: 3
90
200
  summary: Ruby library for parsing stats from Yahoo! Sports pages
91
- test_files:
92
- - test/test_helper.rb
93
- - test/yahoo_sports/base_test.rb
94
- - test/yahoo_sports/mlb_test.rb
95
- - test/yahoo_sports/nba_test.rb
96
- - test/yahoo_sports/nfl_test.rb
97
- - test/yahoo_sports/nhl_test.rb
98
- - test/yahoo_sports_test.rb
201
+ test_files: []
202
+