mlb_gameday 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mlb_gameday.rb +36 -25
- data/lib/mlb_gameday/game.rb +11 -4
- data/lib/mlb_gameday/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ee94ec9e0815136bc3ff608e85f3099cf661f56
|
4
|
+
data.tar.gz: 6d0db220bd3e2dc2dad30fe7e5a20c923c873976
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 751e341a8a5667ae832ec6c6eb172f74a5594adc2f2b639d026669900ba7c90bbb7cfc692952206bc91121e2b944479bee92fc3bb295f8df1790ff5c2b4fd2b2
|
7
|
+
data.tar.gz: ffe1274929c7ca71b4caeda6288de36403184d27b4de4e1c6c0274ea1f7b1715348d6fec8830895299b7836f71cd08ec966be120847791c821e7fe8e3f35edc5
|
data/lib/mlb_gameday.rb
CHANGED
@@ -61,13 +61,12 @@ module MLBGameday
|
|
61
61
|
end
|
62
62
|
|
63
63
|
def game(gid)
|
64
|
-
date = /\A(\d+)_(\d+)_(\d+)_/.match(gid)
|
65
|
-
date = DateTime.new(date[1].to_i, date[2].to_i, date[3].to_i)
|
66
|
-
|
67
64
|
MLBGameday::Game.new(
|
68
65
|
self,
|
69
|
-
|
70
|
-
|
66
|
+
gid,
|
67
|
+
gamecenter: fetch_gamecenter_xml(gid),
|
68
|
+
linescore: fetch_linescore_xml(gid),
|
69
|
+
boxscore: fetch_boxscore_xml(gid)
|
71
70
|
)
|
72
71
|
end
|
73
72
|
|
@@ -82,8 +81,10 @@ module MLBGameday
|
|
82
81
|
|
83
82
|
MLBGameday::Game.new(
|
84
83
|
self,
|
85
|
-
|
86
|
-
|
84
|
+
gid,
|
85
|
+
gamecenter: fetch_gamecenter_xml(gid),
|
86
|
+
linescore: fetch_linescore_xml(gid),
|
87
|
+
boxscore: fetch_boxscore_xml(gid)
|
87
88
|
)
|
88
89
|
end
|
89
90
|
else
|
@@ -95,30 +96,40 @@ module MLBGameday
|
|
95
96
|
|
96
97
|
MLBGameday::Game.new(
|
97
98
|
self,
|
98
|
-
|
99
|
-
|
99
|
+
gid,
|
100
|
+
gamecenter: fetch_gamecenter_xml(gid),
|
101
|
+
linescore: fetch_linescore_xml(gid),
|
102
|
+
boxscore: fetch_boxscore_xml(gid),
|
100
103
|
)
|
101
104
|
end
|
102
105
|
end.compact!
|
103
106
|
end
|
104
107
|
end
|
105
108
|
|
106
|
-
private
|
107
|
-
|
108
109
|
def fetch_scoreboard_xml(date)
|
109
110
|
Nokogiri::XML(open(API_URL + date.strftime("/year_%Y/month_%m/day_%d/miniscoreboard.xml")))
|
110
111
|
end
|
111
112
|
|
112
|
-
def fetch_linescore_xml(
|
113
|
-
|
113
|
+
def fetch_linescore_xml(gid)
|
114
|
+
year, month, day, _ = gid.split("_")
|
115
|
+
|
116
|
+
Nokogiri::XML(open(API_URL + "/year_#{ year }/month_#{ month }/day_#{ day }/gid_#{ gid }/linescore.xml"))
|
114
117
|
end
|
115
118
|
|
116
|
-
def
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
119
|
+
def fetch_boxscore_xml(gid)
|
120
|
+
year, month, day, _ = gid.split("_")
|
121
|
+
|
122
|
+
Nokogiri::XML(open(API_URL + "/year_#{ year }/month_#{ month }/day_#{ day }/gid_#{ gid }/boxscore.xml"))
|
123
|
+
rescue
|
124
|
+
nil
|
125
|
+
end
|
126
|
+
|
127
|
+
def fetch_gamecenter_xml(gid)
|
128
|
+
year, month, day, _ = gid.split("_")
|
129
|
+
|
130
|
+
Nokogiri::XML(open(API_URL + "/year_#{ year }/month_#{ month }/day_#{ day }/gid_#{ gid }/gamecenter.xml"))
|
131
|
+
rescue
|
132
|
+
nil
|
122
133
|
end
|
123
134
|
|
124
135
|
def fetch_batter_xml(id, year: nil)
|
@@ -127,10 +138,10 @@ module MLBGameday
|
|
127
138
|
# We only really want one piece of data from this file...
|
128
139
|
year_data = Nokogiri::XML(open(API_URL + "/year_#{ year }/batters/#{ id }.xml"))
|
129
140
|
|
130
|
-
|
131
|
-
year, month, day, _ =
|
141
|
+
gid = year_data.xpath("//pitching/@game_id").first.value
|
142
|
+
year, month, day, _ = gid.split("/")
|
132
143
|
|
133
|
-
Nokogiri::XML(open(MLBGameday::API_URL + "/year_#{ year }/month_#{ month }/day_#{ day }/gid_#{
|
144
|
+
Nokogiri::XML(open(MLBGameday::API_URL + "/year_#{ year }/month_#{ month }/day_#{ day }/gid_#{ gid.gsub(/[^a-z0-9]/, "_") }/batters/#{ id }.xml"))
|
134
145
|
end
|
135
146
|
|
136
147
|
def fetch_pitcher_xml(id, year: nil)
|
@@ -139,10 +150,10 @@ module MLBGameday
|
|
139
150
|
# We only really want one piece of data from this file...
|
140
151
|
year_data = Nokogiri::XML(open(API_URL + "/year_#{ year }/pitchers/#{ id }.xml"))
|
141
152
|
|
142
|
-
|
143
|
-
year, month, day, _ =
|
153
|
+
gid = year_data.xpath("//pitching/@game_id").first.value
|
154
|
+
year, month, day, _ = gid.split("/")
|
144
155
|
|
145
|
-
Nokogiri::XML(open(MLBGameday::API_URL + "/year_#{ year }/month_#{ month }/day_#{ day }/gid_#{
|
156
|
+
Nokogiri::XML(open(MLBGameday::API_URL + "/year_#{ year }/month_#{ month }/day_#{ day }/gid_#{ gid.gsub(/[^a-z0-9]/, "_") }/pitchers/#{ id }.xml"))
|
146
157
|
end
|
147
158
|
end
|
148
159
|
end
|
data/lib/mlb_gameday/game.rb
CHANGED
@@ -1,12 +1,15 @@
|
|
1
1
|
module MLBGameday
|
2
2
|
class Game
|
3
|
-
def initialize(api, linescore: nil, gamecenter: nil)
|
3
|
+
def initialize(api, gid, linescore: nil, gamecenter: nil, boxscore: nil)
|
4
4
|
@api = api
|
5
|
-
@
|
5
|
+
@gid = gid
|
6
|
+
|
7
|
+
@linescore = linescore
|
6
8
|
@gamecenter = gamecenter
|
9
|
+
@boxscore = boxscore
|
7
10
|
|
8
|
-
@home = @api.team(
|
9
|
-
@away = @api.team(
|
11
|
+
@home = @api.team(linescore.xpath("//game/@home_name_abbrev").first.value)
|
12
|
+
@away = @api.team(linescore.xpath("//game/@away_name_abbrev").first.value)
|
10
13
|
end
|
11
14
|
|
12
15
|
def teams
|
@@ -193,5 +196,9 @@ module MLBGameday
|
|
193
196
|
def gamecenter
|
194
197
|
@gamecenter
|
195
198
|
end
|
199
|
+
|
200
|
+
def boxscore
|
201
|
+
@boxscore
|
202
|
+
end
|
196
203
|
end
|
197
204
|
end
|
data/lib/mlb_gameday/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mlb_gameday
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steven Hoffman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-04-
|
11
|
+
date: 2013-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|