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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aec132ec1fdd0f070d3012089f342fc57154c4c9
4
- data.tar.gz: 0e7aef799fb4444a3b92a80f2fb91368edaa29de
3
+ metadata.gz: 4ee94ec9e0815136bc3ff608e85f3099cf661f56
4
+ data.tar.gz: 6d0db220bd3e2dc2dad30fe7e5a20c923c873976
5
5
  SHA512:
6
- metadata.gz: 320fc58b8406663d86de6c025f6db214de94a90d9673fe52f5aa91d03b6c577b772c4ed3fe6d3e125a0ea1e809055eff41492b730955a3da381a5fd3b9854112
7
- data.tar.gz: 41cd5d32bb3e110b08848a5c80419197cb81b61955384b0f82ba29cc6d92e2fa981f281c110b62d835408ad9a225aa50ad9f84c34a92507eb68a27e8e734e38a
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
- gamecenter: fetch_gamecenter_xml(date, gid),
70
- linescore: fetch_linescore_xml(date, gid)
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
- gamecenter: fetch_gamecenter_xml(date, gid),
86
- linescore: fetch_linescore_xml(date, gid)
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
- gamecenter: fetch_gamecenter_xml(date, gid),
99
- linescore: fetch_linescore_xml(date, gid)
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(date, gameday_link)
113
- Nokogiri::XML(open(API_URL + date.strftime("/year_%Y/month_%m/day_%d/gid_#{ gameday_link }/linescore.xml")))
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 fetch_gamecenter_xml(date, gameday_link)
117
- begin
118
- Nokogiri::XML(open(API_URL + date.strftime("/year_%Y/month_%m/day_%d/gid_#{ gameday_link }/gamecenter.xml")))
119
- rescue Exception
120
- nil
121
- end
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
- game = year_data.xpath("//pitching/@game_id").first.value
131
- year, month, day, _ = game.split("/")
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_#{ game.gsub(/[^a-z0-9]/, "_") }/batters/#{ id }.xml"))
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
- game = year_data.xpath("//pitching/@game_id").first.value
143
- year, month, day, _ = game.split("/")
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_#{ game.gsub(/[^a-z0-9]/, "_") }/pitchers/#{ id }.xml"))
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
@@ -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
- @linescore = linescore
5
+ @gid = gid
6
+
7
+ @linescore = linescore
6
8
  @gamecenter = gamecenter
9
+ @boxscore = boxscore
7
10
 
8
- @home = @api.team(@linescore.xpath("//game/@home_name_abbrev").first.value)
9
- @away = @api.team(@linescore.xpath("//game/@away_name_abbrev").first.value)
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
@@ -1,3 +1,3 @@
1
1
  module MLBGameday
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
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
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-05 00:00:00.000000000 Z
11
+ date: 2013-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler