sports_direct 0.0.2 → 0.0.3

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 nba_basketball_schedule
21
+ get('/basketball/NBA/schedule/schedule_NBA.xml')
22
+ end
23
+
24
+ def nba_basketball_teams(season)
25
+ get("/basketball/NBA/teams/#{season}/teams_NBA.xml")
26
+ end
27
+
20
28
  def ncaa_basketball_schedule
21
29
  get('/basketball/NCAAB/schedule/schedule_NCAAB.xml')
22
30
  end
@@ -0,0 +1,82 @@
1
+ module SportsDirect
2
+ module Basketball
3
+ class NBA
4
+ include Normalization
5
+
6
+ def schedule
7
+ (API.nba_basketball_schedule / 'competition').collect do |event|
8
+ normalize_event(event)
9
+ end
10
+ end
11
+
12
+ def teams
13
+ API.nba_basketball_teams('2010-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.strip!
77
+ name.split.select { |word| word.length > 1 }.join(' ')
78
+ end
79
+ private :normalize_performer_name
80
+ end
81
+ end
82
+ end
@@ -1,6 +1,3 @@
1
- require 'active_support/core_ext/object/try'
2
- require 'active_support/core_ext/string/inflections'
3
-
4
1
  module SportsDirect
5
2
  module Basketball
6
3
  class NCAA
@@ -1,5 +1,6 @@
1
1
  module SportsDirect
2
2
  module Basketball
3
+ autoload :NBA, 'sports_direct/basketball/nba'
3
4
  autoload :NCAA, 'sports_direct/basketball/ncaa'
4
5
  end
5
6
  end
data/lib/sports_direct.rb CHANGED
@@ -1,3 +1,6 @@
1
+ require 'active_support/core_ext/object/try'
2
+ require 'active_support/core_ext/string/inflections'
3
+
1
4
  module SportsDirect
2
5
  autoload :API, 'sports_direct/api'
3
6
  autoload :Normalization, 'sports_direct/normalization'
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 2
9
- version: 0.0.2
8
+ - 3
9
+ version: 0.0.3
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-15 00:00:00 -05:00
17
+ date: 2010-12-16 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -107,6 +107,36 @@ dependencies:
107
107
  version: 2.3.0
108
108
  type: :development
109
109
  version_requirements: *id006
110
+ - !ruby/object:Gem::Dependency
111
+ name: vcr
112
+ prerelease: false
113
+ requirement: &id007 !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - "="
117
+ - !ruby/object:Gem::Version
118
+ segments:
119
+ - 1
120
+ - 4
121
+ - 0
122
+ version: 1.4.0
123
+ type: :development
124
+ version_requirements: *id007
125
+ - !ruby/object:Gem::Dependency
126
+ name: webmock
127
+ prerelease: false
128
+ requirement: &id008 !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - "="
132
+ - !ruby/object:Gem::Version
133
+ segments:
134
+ - 1
135
+ - 6
136
+ - 1
137
+ version: 1.6.1
138
+ type: :development
139
+ version_requirements: *id008
110
140
  description:
111
141
  email:
112
142
  executables: []
@@ -117,6 +147,7 @@ extra_rdoc_files: []
117
147
 
118
148
  files:
119
149
  - lib/sports_direct/api.rb
150
+ - lib/sports_direct/basketball/nba.rb
120
151
  - lib/sports_direct/basketball/ncaa.rb
121
152
  - lib/sports_direct/basketball.rb
122
153
  - lib/sports_direct/normalization.rb