greenmonster 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/.gitignore +6 -0
  2. data/CHANGELOG.markdown +14 -0
  3. data/Gemfile +4 -0
  4. data/{Readme.markdown → README.markdown} +22 -14
  5. data/Rakefile +2 -1
  6. data/doc/Greenmonster/Spider.html +347 -0
  7. data/doc/Greenmonster.html +220 -0
  8. data/doc/GreenmonsterSpiderTest.html +510 -0
  9. data/doc/GreenmonsterTest.html +240 -0
  10. data/doc/Rakefile.html +97 -0
  11. data/doc/created.rid +6 -0
  12. data/doc/images/add.png +0 -0
  13. data/doc/images/brick.png +0 -0
  14. data/doc/images/brick_link.png +0 -0
  15. data/doc/images/bug.png +0 -0
  16. data/doc/images/bullet_black.png +0 -0
  17. data/doc/images/bullet_toggle_minus.png +0 -0
  18. data/doc/images/bullet_toggle_plus.png +0 -0
  19. data/doc/images/date.png +0 -0
  20. data/doc/images/delete.png +0 -0
  21. data/doc/images/find.png +0 -0
  22. data/doc/images/loadingAnimation.gif +0 -0
  23. data/doc/images/macFFBgHack.png +0 -0
  24. data/doc/images/package.png +0 -0
  25. data/doc/images/page_green.png +0 -0
  26. data/doc/images/page_white_text.png +0 -0
  27. data/doc/images/page_white_width.png +0 -0
  28. data/doc/images/plugin.png +0 -0
  29. data/doc/images/ruby.png +0 -0
  30. data/doc/images/tag_blue.png +0 -0
  31. data/doc/images/tag_green.png +0 -0
  32. data/doc/images/transparent.png +0 -0
  33. data/doc/images/wrench.png +0 -0
  34. data/doc/images/wrench_orange.png +0 -0
  35. data/doc/images/zoom.png +0 -0
  36. data/doc/index.html +84 -0
  37. data/doc/js/darkfish.js +153 -0
  38. data/doc/js/jquery.js +18 -0
  39. data/doc/js/navigation.js +142 -0
  40. data/doc/js/search.js +94 -0
  41. data/doc/js/search_index.js +1 -0
  42. data/doc/js/searcher.js +228 -0
  43. data/doc/rdoc.css +543 -0
  44. data/doc/table_of_contents.html +98 -0
  45. data/greenmonster.gemspec +23 -0
  46. data/lib/greenmonster/spider.rb +4 -3
  47. data/lib/greenmonster/version.rb +3 -0
  48. data/lib/greenmonster.rb +7 -3
  49. data/test/test_greenmonster.rb +1 -1
  50. metadata +76 -7
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ test/temp_test.rb
6
+ greenmonster_test_games/*
@@ -0,0 +1,14 @@
1
+ 0.3.0 / 2012-03-16
2
+ ------------------
3
+ * Moved to bundler for dependency management.
4
+ * Local paths now built using Pathname rather than strings for cleaner syntax.
5
+
6
+ 0.2.0 / 2012-03-14
7
+ ------------------
8
+ * Added :all_sport_codes argument for Spider.pull_day to pull all known sport codes for that day.
9
+ * Better error handling and test cases for scenarios where game does not exist.
10
+ * Do not create local files if remote references return 404 errors.
11
+
12
+ 0.1.0 / 2012-03-13
13
+ ------------------
14
+ Spidering for everyone!
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in greenmonster.gemspec
4
+ gemspec
@@ -10,36 +10,44 @@ Usage
10
10
 
11
11
  If you don't want to specify a download location every time you run the spider, you can set a default games folder location using Greenmonster.set_games_location:
12
12
 
13
- # Set games folder location
14
- >> Greenmonster.set_games_folder('/Users/geoff/games/')
13
+ ```ruby
14
+ # Set games folder location
15
+ Greenmonster.set_games_folder('/Users/geoff/games/')
16
+ ```
15
17
 
16
18
  The spider utility has three public class methods: Spider.pull_game, Spider.pull_day, and Spider.pull_days.
17
19
 
18
20
  Spider.pull_game takes a game_id (the folder name of the game on the Gameday server) and a hash of options as arguments. If for some reason the game does not fall in the expected folder for the game's date or sport code, you can add those options to the arguments hash. Other options include :games_folder and :print_games (if false, game IDs are not printed to screen).
19
21
 
20
- # Pulls MLB's 7/4/2011 Toronto @ Boston game
21
- >> Greenmonster::Spider.pull_game('gid_2011_07_04_tormlb_bosmlb_1', {:print_games => false})
22
+ ```ruby
23
+ # Pulls MLB's 7/4/2011 Toronto @ Boston game
24
+ Greenmonster::Spider.pull_game('gid_2011_07_04_tormlb_bosmlb_1', {:print_games => false})
25
+ ```
22
26
 
23
27
  Spider.pull_day takes an hash of options as an argument. Greenmonster will create subfolders by MLB "sport_code" (MLB games fall under 'mlb', various minor league games and non-MLB/MiLB games fall under other sport code designations), and then children folders for years, months, days, and specific games.
24
28
 
25
- # Pulls all MLB games for today
26
- >> Greenmonster::Spider.pull_day({:date => Date.today, :games_folder => './home/geoff/games'})
29
+ ```ruby
30
+ # Pulls all MLB games for today
31
+ Greenmonster::Spider.pull_day({:date => Date.today, :games_folder => './home/geoff/games'})
27
32
 
28
- # Pulls all rookie league games for today
29
- >> Greenmonster::Spider.pull_day({:sport_code => 'rok', :date => Date.today, :games_folder => './home/geoff/games'})
33
+ # Pulls all rookie league games for today
34
+ Greenmonster::Spider.pull_day({:sport_code => 'rok', :date => Date.today, :games_folder => './home/geoff/games'})
30
35
 
31
- # Pulls all games in all sport codes for today
32
- >> Greenmonster::Spider.pull_day({:all_sport_codes => true, :date => Date.today, :games_folder => './home/geoff/games'})
36
+ # Pulls all games in all sport codes for today
37
+ Greenmonster::Spider.pull_day({:all_sport_codes => true, :date => Date.today, :games_folder => './home/geoff/games'})
38
+ ```
33
39
 
34
40
  Spider.pull_days takes a range of dates to process as an argument, plus a hash of arguments to pass to Spider.pull.
35
41
 
36
- # Pulls all MLB games for in April, 2012
37
- >> Greenmonster::Spider.pull_days((Date.new(2012,4,1)..Date.new(2012,4,30)), {:games_folder => './home/geoff/games'})
38
-
42
+ ```ruby
43
+ # Pulls all MLB games for in April, 2012
44
+ Greenmonster::Spider.pull_days((Date.new(2012,4,1)..Date.new(2012,4,30)), {:games_folder => './home/geoff/games'})
45
+ ```
39
46
 
40
47
  Requirements
41
48
  ------------
42
49
  - Ruby 1.9
50
+ - Bundler
43
51
  - Nokogiri
44
52
  - HTTParty
45
53
 
@@ -59,4 +67,4 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
59
67
 
60
68
  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
61
69
 
62
- THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
70
+ THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile CHANGED
@@ -1,3 +1,4 @@
1
+ require "bundler/gem_tasks"
1
2
  require 'rake/testtask'
2
3
 
3
4
  Rake::TestTask.new do |t|
@@ -5,4 +6,4 @@ Rake::TestTask.new do |t|
5
6
  end
6
7
 
7
8
  desc "Run Tests"
8
- task :default => :test
9
+ task :default => :test
@@ -0,0 +1,347 @@
1
+ <!DOCTYPE html>
2
+
3
+ <html>
4
+ <head>
5
+ <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
6
+
7
+ <title>class Greenmonster::Spider - RDoc Documentation</title>
8
+
9
+ <link type="text/css" media="screen" href="../rdoc.css" rel="stylesheet">
10
+
11
+ <script type="text/javascript">
12
+ var rdoc_rel_prefix = "../";
13
+ </script>
14
+
15
+ <script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>
16
+ <script type="text/javascript" charset="utf-8" src="../js/navigation.js"></script>
17
+ <script type="text/javascript" charset="utf-8" src="../js/search_index.js"></script>
18
+ <script type="text/javascript" charset="utf-8" src="../js/search.js"></script>
19
+ <script type="text/javascript" charset="utf-8" src="../js/searcher.js"></script>
20
+ <script type="text/javascript" charset="utf-8" src="../js/darkfish.js"></script>
21
+
22
+
23
+ <body id="top" class="class">
24
+ <nav id="metadata">
25
+ <nav id="home-section" class="section">
26
+ <h3 class="section-header">
27
+ <a href="../index.html">Home</a>
28
+ <a href="../table_of_contents.html#classes">Classes</a>
29
+ <a href="../table_of_contents.html#methods">Methods</a>
30
+ </h3>
31
+ </nav>
32
+
33
+
34
+ <nav id="search-section" class="section project-section" class="initially-hidden">
35
+ <form action="#" method="get" accept-charset="utf-8">
36
+ <h3 class="section-header">
37
+ <input type="text" name="search" placeholder="Search" id="search-field"
38
+ title="Type to search, Up and Down to navigate, Enter to load">
39
+ </h3>
40
+ </form>
41
+
42
+ <ul id="search-results" class="initially-hidden"></ul>
43
+ </nav>
44
+
45
+
46
+ <div id="file-metadata">
47
+ <nav id="file-list-section" class="section">
48
+ <h3 class="section-header">Defined In</h3>
49
+ <ul>
50
+ <li>lib/greenmonster/spider.rb
51
+ </ul>
52
+ </nav>
53
+
54
+
55
+ </div>
56
+
57
+ <div id="class-metadata">
58
+
59
+ <nav id="parent-class-section" class="section">
60
+ <h3 class="section-header">Parent</h3>
61
+
62
+ <p class="link">Object
63
+
64
+ </nav>
65
+
66
+ <!-- Included Modules -->
67
+ <nav id="includes-section" class="section">
68
+ <h3 class="section-header">Included Modules</h3>
69
+
70
+ <ul class="link-list">
71
+
72
+
73
+ <li><span class="include">HTTParty</span>
74
+
75
+
76
+ </ul>
77
+ </nav>
78
+
79
+ <!-- Method Quickref -->
80
+ <nav id="method-list-section" class="section">
81
+ <h3 class="section-header">Methods</h3>
82
+
83
+ <ul class="link-list">
84
+
85
+ <li><a href="#method-c-pull_day">::pull_day</a>
86
+
87
+ <li><a href="#method-c-pull_days">::pull_days</a>
88
+
89
+ <li><a href="#method-c-pull_game">::pull_game</a>
90
+
91
+ </ul>
92
+ </nav>
93
+
94
+ </div>
95
+
96
+ <div id="project-metadata">
97
+ <nav id="fileindex-section" class="section project-section">
98
+ <h3 class="section-header">Pages</h3>
99
+
100
+ <ul>
101
+
102
+ <li class="file"><a href="../Rakefile.html">Rakefile</a>
103
+
104
+ </ul>
105
+ </nav>
106
+
107
+ <nav id="classindex-section" class="section project-section">
108
+ <h3 class="section-header">Class and Module Index</h3>
109
+
110
+ <ul class="link-list">
111
+
112
+ <li><a href="../Greenmonster.html">Greenmonster</a>
113
+
114
+ <li><a href="../Greenmonster/Spider.html">Greenmonster::Spider</a>
115
+
116
+ <li><a href="../GreenmonsterSpiderTest.html">GreenmonsterSpiderTest</a>
117
+
118
+ <li><a href="../GreenmonsterTest.html">GreenmonsterTest</a>
119
+
120
+ </ul>
121
+ </nav>
122
+
123
+ </div>
124
+ </nav>
125
+
126
+ <div id="documentation">
127
+ <h1 class="class">class Greenmonster::Spider</h1>
128
+
129
+ <div id="description" class="description">
130
+
131
+ <p>The Gameday XML <a href="Spider.html">Spider</a> utility</p>
132
+
133
+ </div><!-- description -->
134
+
135
+
136
+
137
+
138
+ <section id="5Buntitled-5D" class="documentation-section">
139
+
140
+
141
+
142
+
143
+
144
+
145
+
146
+
147
+ <!-- Methods -->
148
+
149
+ <section id="public-class-5Buntitled-5D-method-details" class="method-section section">
150
+ <h3 class="section-header">Public Class Methods</h3>
151
+
152
+
153
+ <div id="method-c-pull_day" class="method-detail ">
154
+
155
+ <div class="method-heading">
156
+ <span class="method-name">pull_day</span><span
157
+ class="method-args">(args = {})</span>
158
+ <span class="method-click-advice">click to toggle source</span>
159
+ </div>
160
+
161
+
162
+ <div class="method-description">
163
+
164
+ <p>Pull Gameday XML files for a given date. Default options for the spider
165
+ are to pull games with sport_code of ‘mlb’ (games played by MLB games
166
+ rather than MiLB teams or foreign teams) and to pull games on the current
167
+ date.</p>
168
+
169
+ <p>Example:</p>
170
+
171
+ <pre class="ruby"><span class="ruby-comment"># Pull games from July 4, 2011</span>
172
+ <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-constant">Gameday</span><span class="ruby-operator">::</span><span class="ruby-constant">Spider</span>.<span class="ruby-identifier">pull_day</span>({:<span class="ruby-identifier">date</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2011</span>,<span class="ruby-value">7</span>,<span class="ruby-value">1</span>), :<span class="ruby-identifier">games_folder</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-string">'/Users/geoff/games'</span>})
173
+ </pre>
174
+
175
+ <p>Arguments:</p>
176
+
177
+ <pre>args: (Hash)</pre>
178
+
179
+
180
+
181
+ <div class="method-source-code" id="pull_day-source">
182
+ <pre><span class="ruby-comment"># File lib/greenmonster/spider.rb, line 78</span>
183
+ <span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">pull_day</span>(<span class="ruby-identifier">args</span> = {})
184
+ <span class="ruby-identifier">args</span> = {
185
+ <span class="ruby-value">:date</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-constant">Date</span>.<span class="ruby-identifier">today</span>,
186
+ <span class="ruby-value">:sport_code</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-string">'mlb'</span>,
187
+ }.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">args</span>)
188
+
189
+ <span class="ruby-comment"># Iterate through every hyperlink on the page.</span>
190
+ <span class="ruby-comment"># These links represent the individual game folders</span>
191
+ <span class="ruby-comment"># for each date. Reject any links that aren't to game</span>
192
+ <span class="ruby-comment"># folders or that are to what look like backup game</span>
193
+ <span class="ruby-comment"># folders.</span>
194
+ (<span class="ruby-constant">Nokogiri</span><span class="ruby-operator">::</span><span class="ruby-constant">XML</span>(<span class="ruby-keyword">self</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">gameday_league_and_date_url</span>(<span class="ruby-identifier">args</span>)))<span class="ruby-operator">/</span><span class="ruby-string">&quot;a&quot;</span>).<span class="ruby-identifier">reject</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">l</span><span class="ruby-operator">|</span> <span class="ruby-identifier">l</span>.<span class="ruby-identifier">attribute</span>(<span class="ruby-string">'href'</span>).<span class="ruby-identifier">value</span>[<span class="ruby-value">0</span>,<span class="ruby-value">4</span>] <span class="ruby-operator">!=</span> <span class="ruby-string">&quot;gid_&quot;</span> <span class="ruby-keyword">or</span> <span class="ruby-identifier">l</span>.<span class="ruby-identifier">attribute</span>(<span class="ruby-string">'href'</span>).<span class="ruby-identifier">value</span>[<span class="ruby-value">-5</span>,<span class="ruby-value">4</span>] <span class="ruby-operator">==</span> <span class="ruby-string">&quot;_bak&quot;</span>}.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">e</span><span class="ruby-operator">|</span>
195
+ <span class="ruby-keyword">self</span>.<span class="ruby-identifier">pull_game</span>(<span class="ruby-identifier">e</span>.<span class="ruby-identifier">attribute</span>(<span class="ruby-string">'href'</span>).<span class="ruby-identifier">value</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-string">'/'</span>,<span class="ruby-string">''</span>),<span class="ruby-identifier">args</span>)
196
+ <span class="ruby-keyword">end</span>
197
+
198
+ <span class="ruby-keyword">return</span> <span class="ruby-identifier">gameday_league_and_date_url</span>(<span class="ruby-identifier">args</span>)
199
+ <span class="ruby-keyword">end</span></pre>
200
+ </div><!-- pull_day-source -->
201
+
202
+ </div>
203
+
204
+
205
+
206
+
207
+ </div><!-- pull_day-method -->
208
+
209
+
210
+ <div id="method-c-pull_days" class="method-detail ">
211
+
212
+ <div class="method-heading">
213
+ <span class="method-name">pull_days</span><span
214
+ class="method-args">(range,args = {})</span>
215
+ <span class="method-click-advice">click to toggle source</span>
216
+ </div>
217
+
218
+
219
+ <div class="method-description">
220
+
221
+ <p>Pull Gameday XML files for a range of dates. The args hash passes arguments
222
+ like games_folder location on to Spider.pull.</p>
223
+
224
+ <p>Example:</p>
225
+
226
+ <pre class="ruby"><span class="ruby-comment"># Pull all games in MLB in July 2011</span>
227
+ <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-constant">Gameday</span><span class="ruby-operator">::</span><span class="ruby-constant">Spider</span>.<span class="ruby-identifier">pull_days</span>(<span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2011</span>,<span class="ruby-value">7</span>,<span class="ruby-value">1</span>)<span class="ruby-operator">..</span><span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">2011</span>,<span class="ruby-value">7</span>,<span class="ruby-value">31</span>), {:<span class="ruby-identifier">games_folder</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-string">'/Users/geoff/games'</span>})
228
+ </pre>
229
+
230
+ <p>Arguments:</p>
231
+
232
+ <pre>range: (Range)
233
+ args: (Hash)</pre>
234
+
235
+
236
+
237
+ <div class="method-source-code" id="pull_days-source">
238
+ <pre><span class="ruby-comment"># File lib/greenmonster/spider.rb, line 108</span>
239
+ <span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">pull_days</span>(<span class="ruby-identifier">range</span>,<span class="ruby-identifier">args</span> = {})
240
+ <span class="ruby-identifier">range</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">day</span><span class="ruby-operator">|</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">pull_day</span>(<span class="ruby-identifier">args</span>.<span class="ruby-identifier">merge</span>({<span class="ruby-value">:date</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">day</span>}))}
241
+ <span class="ruby-keyword">end</span></pre>
242
+ </div><!-- pull_days-source -->
243
+
244
+ </div>
245
+
246
+
247
+
248
+
249
+ </div><!-- pull_days-method -->
250
+
251
+
252
+ <div id="method-c-pull_game" class="method-detail ">
253
+
254
+ <div class="method-heading">
255
+ <span class="method-name">pull_game</span><span
256
+ class="method-args">(game_id,args = {})</span>
257
+ <span class="method-click-advice">click to toggle source</span>
258
+ </div>
259
+
260
+
261
+ <div class="method-description">
262
+
263
+ <p>Pull Gameday XML files for a given game, specified by the game ID. If date
264
+ and sport code are not specified as options, these values are guessed from
265
+ the game ID string using the home team’s sport code and the date from the
266
+ scheduled date values in the game ID.</p>
267
+
268
+ <p>Example:</p>
269
+
270
+ <pre class="ruby"><span class="ruby-operator">&gt;&gt;</span> <span class="ruby-constant">Gameday</span><span class="ruby-operator">::</span><span class="ruby-constant">Spider</span>.<span class="ruby-identifier">pull_game</span>(<span class="ruby-string">''</span>,{:<span class="ruby-identifier">games_folder</span> =<span class="ruby-operator">&gt;</span> })
271
+ </pre>
272
+
273
+
274
+
275
+ <div class="method-source-code" id="pull_game-source">
276
+ <pre><span class="ruby-comment"># File lib/greenmonster/spider.rb, line 15</span>
277
+ <span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">pull_game</span>(<span class="ruby-identifier">game_id</span>,<span class="ruby-identifier">args</span> = {})
278
+ <span class="ruby-identifier">args</span> = {
279
+ <span class="ruby-value">:date</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">args</span>[<span class="ruby-value">:date</span>] <span class="ruby-operator">||</span> <span class="ruby-constant">Date</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">game_id</span>[<span class="ruby-value">4</span>,<span class="ruby-value">4</span>].<span class="ruby-identifier">to_i</span>, <span class="ruby-identifier">game_id</span>[<span class="ruby-value">9</span>,<span class="ruby-value">2</span>].<span class="ruby-identifier">to_i</span>, <span class="ruby-identifier">game_id</span>[<span class="ruby-value">12</span>,<span class="ruby-value">2</span>].<span class="ruby-identifier">to_i</span>),
280
+ <span class="ruby-value">:sport_code</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">args</span>[<span class="ruby-value">:sport_code</span>] <span class="ruby-operator">||</span> <span class="ruby-identifier">game_id</span>[<span class="ruby-value">25</span>,<span class="ruby-value">3</span>],
281
+ <span class="ruby-value">:print_games</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword">true</span>,
282
+ <span class="ruby-value">:games_folder</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-constant">Greenmonster</span>.<span class="ruby-identifier">games_folder</span>
283
+ }.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">args</span>)
284
+
285
+ <span class="ruby-identifier">puts</span> <span class="ruby-identifier">game_id</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">args</span>[<span class="ruby-value">:print_games</span>]
286
+
287
+ <span class="ruby-identifier">raise</span> <span class="ruby-string">&quot;Games folder location required.&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">args</span>[<span class="ruby-value">:games_folder</span>].<span class="ruby-identifier">nil?</span>
288
+
289
+ <span class="ruby-identifier">paths</span> = {
290
+ <span class="ruby-value">:localGameFolder</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-node">&quot;#{args[:games_folder]}/#{args[:sport_code]}/#{format_date_as_folder(args[:date])}/#{game_id}/&quot;</span>,
291
+ <span class="ruby-value">:mlbGameFolder</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-node">&quot;#{gameday_league_and_date_url(args)}/#{game_id}/&quot;</span>
292
+ }
293
+
294
+ <span class="ruby-constant">FileUtils</span>.<span class="ruby-identifier">mkdir_p</span> <span class="ruby-identifier">paths</span>[<span class="ruby-value">:localGameFolder</span>] <span class="ruby-operator">+</span> <span class="ruby-string">'inning'</span>
295
+
296
+ <span class="ruby-keyword">begin</span>
297
+ <span class="ruby-comment"># Always copy linescore first. If we can't get this</span>
298
+ <span class="ruby-comment"># data, all other game data is useless.</span>
299
+ <span class="ruby-identifier">copy_gameday_xml</span>(<span class="ruby-string">'linescore.xml'</span>,<span class="ruby-identifier">paths</span>)
300
+
301
+ <span class="ruby-keyword">if</span> <span class="ruby-identifier">args</span>[<span class="ruby-value">:date</span>].<span class="ruby-identifier">year</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">2007</span>
302
+ <span class="ruby-identifier">copy_gameday_xml</span>(<span class="ruby-string">'inning_all.xml'</span>,<span class="ruby-identifier">paths</span>)
303
+ <span class="ruby-identifier">copy_gameday_xml</span>(<span class="ruby-string">'inning_hit.xml'</span>,<span class="ruby-identifier">paths</span>)
304
+ <span class="ruby-keyword">else</span>
305
+ <span class="ruby-comment"># Iterate through the inning files, but skip inning </span>
306
+ <span class="ruby-comment"># files numbered 0 (some bad spring training data).</span>
307
+ <span class="ruby-comment"># Necessary for games prior to 2008 because there is</span>
308
+ <span class="ruby-comment"># no inning_all.xml file in older games.</span>
309
+ (<span class="ruby-constant">Nokogiri</span><span class="ruby-operator">::</span><span class="ruby-constant">XML</span>(<span class="ruby-keyword">self</span>.<span class="ruby-identifier">get</span>(<span class="ruby-node">&quot;#{paths[:mlbGameFolder]}/inning/&quot;</span>).<span class="ruby-identifier">body</span>).<span class="ruby-identifier">search</span>(<span class="ruby-string">'a'</span>)).<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">ic</span><span class="ruby-operator">|</span>
310
+ <span class="ruby-identifier">copy_gameday_xml</span>(<span class="ruby-identifier">ic</span>.<span class="ruby-identifier">attribute</span>(<span class="ruby-string">'href'</span>).<span class="ruby-identifier">value</span>,<span class="ruby-identifier">paths</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">ic</span>.<span class="ruby-identifier">attribute</span>(<span class="ruby-string">'href'</span>).<span class="ruby-identifier">value</span>[<span class="ruby-value">-3</span>,<span class="ruby-value">3</span>] <span class="ruby-operator">==</span> <span class="ruby-string">&quot;xml&quot;</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">ic</span>.<span class="ruby-identifier">attribute</span>(<span class="ruby-string">'href'</span>).<span class="ruby-identifier">value</span>[<span class="ruby-value">-6</span>,<span class="ruby-value">6</span>] <span class="ruby-operator">==</span> <span class="ruby-string">&quot;_0.xml&quot;</span> <span class="ruby-keyword">or</span> <span class="ruby-identifier">ic</span>.<span class="ruby-identifier">attribute</span>(<span class="ruby-string">'href'</span>).<span class="ruby-identifier">value</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-string">'Score'</span>)
311
+ <span class="ruby-keyword">end</span>
312
+ <span class="ruby-keyword">end</span>
313
+
314
+ <span class="ruby-comment"># Copy base data files </span>
315
+ <span class="ruby-comment"># (if inning data wasn't there, this gets skipped)</span>
316
+ [<span class="ruby-string">'boxscore.xml'</span>,<span class="ruby-string">'eventLog.xml'</span>,<span class="ruby-string">'players.xml'</span>].<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">file</span><span class="ruby-operator">|</span>
317
+ <span class="ruby-identifier">copy_gameday_xml</span>(<span class="ruby-identifier">file</span>,<span class="ruby-identifier">paths</span>)
318
+ <span class="ruby-keyword">end</span>
319
+ <span class="ruby-keyword">rescue</span> <span class="ruby-constant">StandardError</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">bang</span>
320
+ <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;Unable to download some data for #{e.attribute('href').value}&quot;</span>
321
+ <span class="ruby-keyword">end</span>
322
+
323
+ <span class="ruby-keyword">return</span> <span class="ruby-identifier">game_id</span>
324
+ <span class="ruby-keyword">end</span></pre>
325
+ </div><!-- pull_game-source -->
326
+
327
+ </div>
328
+
329
+
330
+
331
+
332
+ </div><!-- pull_game-method -->
333
+
334
+
335
+ </section><!-- public-class-method-details -->
336
+
337
+ </section><!-- 5Buntitled-5D -->
338
+
339
+ </div><!-- documentation -->
340
+
341
+
342
+ <footer id="validator-badges">
343
+ <p><a href="http://validator.w3.org/check/referer">[Validate]</a>
344
+ <p>Generated by <a href="https://github.com/rdoc/rdoc">RDoc</a> 3.12.
345
+ <p>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish Rdoc Generator</a> 3.
346
+ </footer>
347
+