sports_direct 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -17,6 +17,14 @@ module SportsDirect
17
17
  end
18
18
 
19
19
  class << self
20
+ def baseball_mlb_schedule
21
+ get('/baseball/MLB/schedule/schedule_MLB.xml')
22
+ end
23
+
24
+ def baseball_mlb_teams(season)
25
+ get("/baseball/MLB/teams/#{season}/teams_MLB.xml")
26
+ end
27
+
20
28
  def basketball_nba_schedule
21
29
  get('/basketball/NBA/schedule/schedule_NBA.xml')
22
30
  end
@@ -0,0 +1,85 @@
1
+ module SportsDirect
2
+ module Baseball
3
+ class MLB
4
+ include Normalization
5
+
6
+ def schedule
7
+ (API.baseball_mlb_schedule / 'competition').collect do |event|
8
+ normalize_event(event)
9
+ end
10
+ end
11
+
12
+ def teams
13
+ API.baseball_mlb_teams('2011') / 'team'
14
+ end
15
+ private :teams
16
+
17
+ def team_name(id)
18
+ id = id.split(':').last.to_i if id.is_a?(String)
19
+ team_names[id]
20
+ end
21
+ private :team_name
22
+
23
+ def team_names
24
+ @team_names ||= Hash[teams.collect do |team|
25
+ name = team.at('name').text
26
+ nick = team.at('name[@type="nick"]/text()').to_s
27
+ full_name = normalize_performer_name("#{name} #{nick}")
28
+
29
+ [team.at('id').text.split(':').last.to_i, full_name]
30
+ end]
31
+ end
32
+ private :team_names
33
+
34
+ def normalize_event(event)
35
+ details = event.at('details')
36
+ venue = details.at('venue')
37
+ locality = venue.at('location/city').text
38
+ region = venue.at('location/state').try(:text)
39
+ home_name = team_name(event.at('home-team-content/team/id').text)
40
+ away_name = team_name(event.at('away-team-content/team/id').text)
41
+ event_name = "#{home_name} vs. #{away_name}"
42
+
43
+ if details.at('competition-type').text != 'Regular Season'
44
+ event_name = "#{details.at('competition-type').text}: #{event_name}"
45
+ end
46
+
47
+ {
48
+ :id => event.at('id').text.split(':').last,
49
+ :event_name => event_name,
50
+ :occurs_at => normalize_date(
51
+ event.at('start-date').text,
52
+ event.at('timezone').text,
53
+ locality,
54
+ region
55
+ ),
56
+ :occurs_at_utc => normalize_date(
57
+ event.at('start-date').text,
58
+ event.at('timezone').text,
59
+ locality,
60
+ region,
61
+ true
62
+ ),
63
+ :tbd => details.at('date-tbd').text == 'true',
64
+ :venue_name => normalize_venue_name(venue.at('name').text),
65
+ :locality => locality,
66
+ :region => normalize_region(region.to_s),
67
+ :country => venue.at('location/country').text,
68
+ :home_name => home_name,
69
+ :away_name => away_name
70
+ }
71
+ end
72
+ private :normalize_event
73
+
74
+ def normalize_performer_name(name)
75
+ name = name.split.uniq.join(' ')
76
+ name.sub!(/\bChi\./, 'Chicago')
77
+ name.sub!(/\bLA\b/, 'Los Angeles')
78
+ name.sub!(/\bNY\b/, 'New York')
79
+ name.strip!
80
+ name.split.select { |word| word.length > 1 }.join(' ')
81
+ end
82
+ private :normalize_performer_name
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,5 @@
1
+ module SportsDirect
2
+ module Baseball
3
+ autoload :MLB, 'sports_direct/baseball/mlb'
4
+ end
5
+ end
@@ -73,6 +73,7 @@ module SportsDirect
73
73
 
74
74
  def normalize_performer_name(name)
75
75
  name = name.split.uniq.join(' ')
76
+ name.sub!(/\bL\.A\./, 'Los Angeles')
76
77
  name.strip!
77
78
  name.split.select { |word| word.length > 1 }.join(' ')
78
79
  end
data/lib/sports_direct.rb CHANGED
@@ -5,6 +5,7 @@ module SportsDirect
5
5
  autoload :API, 'sports_direct/api'
6
6
  autoload :Normalization, 'sports_direct/normalization'
7
7
 
8
+ autoload :Baseball, 'sports_direct/baseball'
8
9
  autoload :Basketball, 'sports_direct/basketball'
9
10
  autoload :Hockey, 'sports_direct/hockey'
10
11
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 4
9
- version: 0.0.4
8
+ - 5
9
+ version: 0.0.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - Tyler Hunt
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-12-17 00:00:00 -05:00
17
+ date: 2010-12-21 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -147,6 +147,8 @@ extra_rdoc_files: []
147
147
 
148
148
  files:
149
149
  - lib/sports_direct/api.rb
150
+ - lib/sports_direct/baseball/mlb.rb
151
+ - lib/sports_direct/baseball.rb
150
152
  - lib/sports_direct/basketball/nba.rb
151
153
  - lib/sports_direct/basketball/ncaa.rb
152
154
  - lib/sports_direct/basketball.rb