sports_direct 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
data/lib/sports_direct/api.rb
CHANGED
@@ -17,22 +17,30 @@ module SportsDirect
|
|
17
17
|
end
|
18
18
|
|
19
19
|
class << self
|
20
|
-
def
|
20
|
+
def basketball_nba_schedule
|
21
21
|
get('/basketball/NBA/schedule/schedule_NBA.xml')
|
22
22
|
end
|
23
23
|
|
24
|
-
def
|
24
|
+
def basketball_nba_teams(season)
|
25
25
|
get("/basketball/NBA/teams/#{season}/teams_NBA.xml")
|
26
26
|
end
|
27
27
|
|
28
|
-
def
|
28
|
+
def basketball_ncaa_schedule
|
29
29
|
get('/basketball/NCAAB/schedule/schedule_NCAAB.xml')
|
30
30
|
end
|
31
31
|
|
32
|
-
def
|
32
|
+
def basketball_ncaa_teams(season)
|
33
33
|
get("/basketball/NCAAB/teams/#{season}/teams_NCAAB.xml")
|
34
34
|
end
|
35
35
|
|
36
|
+
def hockey_nhl_schedule
|
37
|
+
get('/hockey/NHL/schedule/schedule_NHL.xml')
|
38
|
+
end
|
39
|
+
|
40
|
+
def hockey_nhl_teams(season)
|
41
|
+
get("/hockey/NHL/teams/#{season}/teams_NHL.xml")
|
42
|
+
end
|
43
|
+
|
36
44
|
def get(*args)
|
37
45
|
response = super
|
38
46
|
|
@@ -49,6 +57,7 @@ module SportsDirect
|
|
49
57
|
rescue Errno::ETIMEDOUT
|
50
58
|
raise Timeout.new($!.message)
|
51
59
|
end
|
60
|
+
private :get
|
52
61
|
end
|
53
62
|
end
|
54
63
|
end
|
@@ -4,13 +4,13 @@ module SportsDirect
|
|
4
4
|
include Normalization
|
5
5
|
|
6
6
|
def schedule
|
7
|
-
(API.
|
7
|
+
(API.basketball_nba_schedule / 'competition').collect do |event|
|
8
8
|
normalize_event(event)
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
12
|
def teams
|
13
|
-
API.
|
13
|
+
API.basketball_nba_teams('2010-2011') / 'team'
|
14
14
|
end
|
15
15
|
private :teams
|
16
16
|
|
@@ -4,13 +4,13 @@ module SportsDirect
|
|
4
4
|
include Normalization
|
5
5
|
|
6
6
|
def schedule
|
7
|
-
(API.
|
7
|
+
(API.basketball_ncaa_schedule / 'competition').collect do |event|
|
8
8
|
normalize_event(event)
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
12
|
def teams
|
13
|
-
API.
|
13
|
+
API.basketball_ncaa_teams('2010-2011') / 'team'
|
14
14
|
end
|
15
15
|
private :teams
|
16
16
|
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module SportsDirect
|
2
|
+
module Hockey
|
3
|
+
class NHL
|
4
|
+
include Normalization
|
5
|
+
|
6
|
+
def schedule
|
7
|
+
(API.hockey_nhl_schedule / 'competition').collect do |event|
|
8
|
+
normalize_event(event)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def teams
|
13
|
+
API.hockey_nhl_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.sub!(/\bNY\b/, 'New York')
|
77
|
+
name.strip!
|
78
|
+
name.split.select { |word| word.length > 1 }.join(' ')
|
79
|
+
end
|
80
|
+
private :normalize_performer_name
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
data/lib/sports_direct.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 4
|
9
|
+
version: 0.0.4
|
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
|
+
date: 2010-12-17 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -150,6 +150,8 @@ files:
|
|
150
150
|
- lib/sports_direct/basketball/nba.rb
|
151
151
|
- lib/sports_direct/basketball/ncaa.rb
|
152
152
|
- lib/sports_direct/basketball.rb
|
153
|
+
- lib/sports_direct/hockey/nhl.rb
|
154
|
+
- lib/sports_direct/hockey.rb
|
153
155
|
- lib/sports_direct/normalization.rb
|
154
156
|
- lib/sports_direct.rb
|
155
157
|
has_rdoc: true
|