modsulator 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/lib/doc/Modsulator.html +725 -0
  4. data/lib/doc/_index.html +101 -0
  5. data/lib/doc/class_list.html +58 -0
  6. data/lib/doc/css/common.css +1 -0
  7. data/lib/doc/css/full_list.css +57 -0
  8. data/lib/doc/css/style.css +339 -0
  9. data/lib/doc/file_list.html +57 -0
  10. data/lib/doc/frames.html +26 -0
  11. data/lib/doc/index.html +101 -0
  12. data/lib/doc/js/app.js +219 -0
  13. data/lib/doc/js/full_list.js +181 -0
  14. data/lib/doc/js/jquery.js +4 -0
  15. data/lib/doc/method_list.html +87 -0
  16. data/lib/doc/top-level-namespace.html +112 -0
  17. data/lib/modsulator/mods-3-6.xsd +1512 -0
  18. data/lib/modsulator/modsulator.xsd +3 -3
  19. data/lib/modsulator/modsulator_template.xml +413 -21
  20. data/spec/fixtures/36_Fitch_Chavez.xml +2806 -0
  21. data/spec/fixtures/36_Fitch_King.xml +2560 -0
  22. data/spec/fixtures/36_Heckrotte_ChartsOfCoastSurvey.xml +1835 -0
  23. data/spec/fixtures/36_M1463_AV_manifest.xml +2373 -0
  24. data/spec/fixtures/36_Matter_manifest.xml +3309 -0
  25. data/spec/fixtures/36_PosadaSpreadsheet.xml +1259 -0
  26. data/spec/fixtures/36_SC1049_metadata.xml +18644 -0
  27. data/spec/fixtures/36_ars0056_manifest.xml +9728 -0
  28. data/spec/fixtures/36_crowdsourcing_bridget_1.xml +606 -0
  29. data/spec/fixtures/36_crowdsourcing_bridget_2.xml +3433 -0
  30. data/spec/fixtures/36_edition_physLoc_intmediatype.xml +41 -0
  31. data/spec/fixtures/36_filled_template_20160711.xml +458 -0
  32. data/spec/fixtures/36_invalid_crowdsourcing_bridget_1.xml +606 -0
  33. data/spec/fixtures/36_location_url.xml +14 -0
  34. data/spec/fixtures/36_manifest_v0174.xml +1026 -0
  35. data/spec/fixtures/36_point_coord_test.xml +23 -0
  36. data/spec/fixtures/36_roman_coins_mods.xml +7634 -0
  37. data/spec/fixtures/Fitch_Chavez.xml +90 -90
  38. data/spec/fixtures/Fitch_King.xml +75 -75
  39. data/spec/fixtures/Heckrotte_ChartsOfCoastSurvey.xml +15 -15
  40. data/spec/fixtures/M1463_AV_manifest.xml +68 -68
  41. data/spec/fixtures/Matter_manifest.xml +292 -292
  42. data/spec/fixtures/PosadaSpreadsheet.xml +157 -157
  43. data/spec/fixtures/SC1049_metadata.xml +384 -384
  44. data/spec/fixtures/ars0056_manifest.xml +258 -258
  45. data/spec/fixtures/crowdsourcing_bridget_1.xml +20 -20
  46. data/spec/fixtures/crowdsourcing_bridget_2.xml +130 -130
  47. data/spec/fixtures/edition_physLoc_intmediatype.xml +2 -2
  48. data/spec/fixtures/filled_template_20160711.xml +1 -1
  49. data/spec/fixtures/invalid_crowdsourcing_bridget_1.xml +20 -20
  50. data/spec/fixtures/location_url.xml +1 -1
  51. data/spec/fixtures/manifest_v0174.xml +31 -31
  52. data/spec/fixtures/point_coord_test.xml +1 -1
  53. data/spec/fixtures/roman_coins_mods.xml +173 -173
  54. data/spec/integration_tests/integration_spec.rb +4 -3
  55. metadata +81 -33
  56. data/lib/modsulator/mods-3-5.xsd +0 -1463
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a3233a0697828fef131d04c823f26e0ba4c0e6ad801866acb37b38cf6b3d41ef
4
- data.tar.gz: 55325e212b9ead23a751873a9c08de5630ad3bb2eaf02801cb9ad55efdb805b3
3
+ metadata.gz: 39162fab117676bddfc7a0276fccb24abea595b43c43d44e90155006eb09e97c
4
+ data.tar.gz: 2b6deeaa78d100b207f13bef9dca5e65930643d7c38622910ac3257e47a815a0
5
5
  SHA512:
6
- metadata.gz: 9e6b198514ba6b636ea09fd4b69e0cbfddde9292fb30cdd05ee1a443956f5c8777ab07c743ad16c1c67cb061d00c4791c47958de7b46c14ab996084f69114b1e
7
- data.tar.gz: ef29e80059adafba49db70c2f16669cff81a343770f4cadf2669c0590314b63ca25e37f4c1ca0802f773814ed5a36390e2fb11ce96736fe0da7858faf53d3f6c
6
+ metadata.gz: 2aa84cc5bf9d2c22d1ebe89b230c343cd1368f4b716844db1dfb994f1fdd678fa5ee43e8bfd91c41f62a0dfacbde7db4acbef69fa303653f712e1638cf8d1b2c
7
+ data.tar.gz: 67b747c305274dd3560a395091172ae76f15e91af7cb5649ae0ddc412522f3cd401977dad85717e2cdfc5246497f6f9f1a62942a1632468eef9dba74fa0a6f35
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- [![Build Status](https://travis-ci.org/sul-dlss/modsulator.svg?branch=master)](https://travis-ci.org/sul-dlss/modsulator) [![Coverage Status](https://coveralls.io/repos/sul-dlss/modsulator/badge.png)](https://coveralls.io/r/sul-dlss/modsulator) [![Dependency Status](https://gemnasium.com/sul-dlss/modsulator.svg)](https://gemnasium.com/sul-dlss/modsulator) [![Gem Version](https://badge.fury.io/rb/modsulator.svg)](http://badge.fury.io/rb/modsulator) [![Code Climate](https://codeclimate.com/github/sul-dlss/modsulator/badges/gpa.svg)](https://codeclimate.com/github/sul-dlss/modsulator)
1
+ [![Build Status](https://travis-ci.org/sul-dlss/modsulator.svg?branch=master)](https://travis-ci.org/sul-dlss/modsulator) [![Coverage Status](https://coveralls.io/repos/sul-dlss/modsulator/badge.png)](https://coveralls.io/r/sul-dlss/modsulator) [![Gem Version](https://badge.fury.io/rb/modsulator.svg)](http://badge.fury.io/rb/modsulator) [![Code Climate](https://codeclimate.com/github/sul-dlss/modsulator/badges/gpa.svg)](https://codeclimate.com/github/sul-dlss/modsulator)
2
2
 
3
3
  # modsulator
4
4
  Produce Stanford MODS from spreadsheets.
@@ -0,0 +1,725 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6
+ <title>
7
+ Class: Modsulator
8
+
9
+ &mdash; Documentation by YARD 0.8.7.6
10
+
11
+ </title>
12
+
13
+ <link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8" />
14
+
15
+ <link rel="stylesheet" href="css/common.css" type="text/css" charset="utf-8" />
16
+
17
+ <script type="text/javascript" charset="utf-8">
18
+ hasFrames = window.top.frames.main ? true : false;
19
+ relpath = '';
20
+ framesUrl = "frames.html#!Modsulator.html";
21
+ </script>
22
+
23
+
24
+ <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
25
+
26
+ <script type="text/javascript" charset="utf-8" src="js/app.js"></script>
27
+
28
+
29
+ </head>
30
+ <body>
31
+ <div id="header">
32
+ <div id="menu">
33
+
34
+ <a href="_index.html">Index (M)</a> &raquo;
35
+
36
+
37
+ <span class="title">Modsulator</span>
38
+
39
+
40
+ <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
41
+ </div>
42
+
43
+ <div id="search">
44
+
45
+ <a class="full_list_link" id="class_list_link"
46
+ href="class_list.html">
47
+ Class List
48
+ </a>
49
+
50
+ <a class="full_list_link" id="method_list_link"
51
+ href="method_list.html">
52
+ Method List
53
+ </a>
54
+
55
+ <a class="full_list_link" id="file_list_link"
56
+ href="file_list.html">
57
+ File List
58
+ </a>
59
+
60
+ </div>
61
+ <div class="clear"></div>
62
+ </div>
63
+
64
+ <iframe id="search_frame"></iframe>
65
+
66
+ <div id="content"><h1>Class: Modsulator
67
+
68
+
69
+
70
+ </h1>
71
+
72
+ <dl class="box">
73
+
74
+ <dt class="r1">Inherits:</dt>
75
+ <dd class="r1">
76
+ <span class="inheritName">Object</span>
77
+
78
+ <ul class="fullTree">
79
+ <li>Object</li>
80
+
81
+ <li class="next">Modsulator</li>
82
+
83
+ </ul>
84
+ <a href="#" class="inheritanceTree">show all</a>
85
+
86
+ </dd>
87
+
88
+
89
+
90
+
91
+
92
+
93
+
94
+
95
+
96
+ <dt class="r2 last">Defined in:</dt>
97
+ <dd class="r2 last">modsulator.rb</dd>
98
+
99
+ </dl>
100
+ <div class="clear"></div>
101
+
102
+
103
+
104
+
105
+
106
+
107
+
108
+
109
+
110
+ <h2>
111
+ Instance Method Summary
112
+ <small>(<a href="#" class="summary_toggle">collapse</a>)</small>
113
+ </h2>
114
+
115
+ <ul class="summary">
116
+
117
+ <li class="public ">
118
+ <span class="summary_signature">
119
+
120
+ <a href="#generate_normalized_mods-instance_method" title="#generate_normalized_mods (instance method)">- (Object) <strong>generate_normalized_mods</strong>(template_filename, spreadsheet_filename, output_directory) </a>
121
+
122
+
123
+
124
+ </span>
125
+
126
+
127
+
128
+
129
+
130
+
131
+
132
+
133
+
134
+ <span class="summary_desc"><div class='inline'>
135
+ <p>Generates normalized (Stanford) MODS XML, writing to files.</p>
136
+ </div></span>
137
+
138
+ </li>
139
+
140
+
141
+ <li class="public ">
142
+ <span class="summary_signature">
143
+
144
+ <a href="#generate_xml-instance_method" title="#generate_xml (instance method)">- (Object) <strong>generate_xml</strong>(mf, template_xml, row_number) </a>
145
+
146
+
147
+
148
+ </span>
149
+
150
+
151
+
152
+
153
+
154
+
155
+
156
+
157
+
158
+ <span class="summary_desc"><div class='inline'>
159
+ <p>Write XML to file.</p>
160
+ </div></span>
161
+
162
+ </li>
163
+
164
+
165
+ <li class="public ">
166
+ <span class="summary_signature">
167
+
168
+ <a href="#load_spreadsheet-instance_method" title="#load_spreadsheet (instance method)">- (Object) <strong>load_spreadsheet</strong>(filename) </a>
169
+
170
+
171
+
172
+ </span>
173
+
174
+
175
+
176
+
177
+
178
+
179
+
180
+
181
+
182
+ <span class="summary_desc"><div class='inline'></div></span>
183
+
184
+ </li>
185
+
186
+
187
+ <li class="public ">
188
+ <span class="summary_signature">
189
+
190
+ <a href="#open_spreadsheet-instance_method" title="#open_spreadsheet (instance method)">- (Object) <strong>open_spreadsheet</strong>(filename) </a>
191
+
192
+
193
+
194
+ </span>
195
+
196
+
197
+
198
+
199
+
200
+
201
+
202
+
203
+
204
+ <span class="summary_desc"><div class='inline'>
205
+ <p>Open spreadsheet based on filename extension.</p>
206
+ </div></span>
207
+
208
+ </li>
209
+
210
+
211
+ <li class="public ">
212
+ <span class="summary_signature">
213
+
214
+ <a href="#validate_headers-instance_method" title="#validate_headers (instance method)">- (Array&lt;String&gt;) <strong>validate_headers</strong>(spreadsheet_headers, template_xml) </a>
215
+
216
+
217
+
218
+ </span>
219
+
220
+
221
+
222
+
223
+
224
+
225
+
226
+
227
+
228
+ <span class="summary_desc"><div class='inline'>
229
+ <p>Checks that all the headers in the spreadsheet has a corresponding entry in
230
+ the XML template.</p>
231
+ </div></span>
232
+
233
+ </li>
234
+
235
+
236
+ </ul>
237
+
238
+
239
+
240
+
241
+ <div id="instance_method_details" class="method_details_list">
242
+ <h2>Instance Method Details</h2>
243
+
244
+
245
+ <div class="method_details first">
246
+ <h3 class="signature first" id="generate_normalized_mods-instance_method">
247
+
248
+ - (<tt>Object</tt>) <strong>generate_normalized_mods</strong>(template_filename, spreadsheet_filename, output_directory)
249
+
250
+
251
+
252
+
253
+
254
+ </h3><div class="docstring">
255
+ <div class="discussion">
256
+
257
+ <p>Generates normalized (Stanford) MODS XML, writing to files.</p>
258
+
259
+
260
+ </div>
261
+ </div>
262
+ <div class="tags">
263
+ <p class="tag_title">Parameters:</p>
264
+ <ul class="param">
265
+
266
+ <li>
267
+
268
+ <span class='name'>template_filename</span>
269
+
270
+
271
+ <span class='type'>(<tt>String</tt>)</span>
272
+
273
+
274
+
275
+ &mdash;
276
+ <div class='inline'>
277
+ <p>The full path to the desired template file (a spreadsheet).</p>
278
+ </div>
279
+
280
+ </li>
281
+
282
+ <li>
283
+
284
+ <span class='name'>spreadsheet_filename</span>
285
+
286
+
287
+ <span class='type'>(<tt>String</tt>)</span>
288
+
289
+
290
+
291
+ &mdash;
292
+ <div class='inline'>
293
+ <p>The full path to the input spreadsheet. One XML file will be generated per
294
+ data row in this spreadsheet.</p>
295
+ </div>
296
+
297
+ </li>
298
+
299
+ <li>
300
+
301
+ <span class='name'>output_directory</span>
302
+
303
+
304
+ <span class='type'>(<tt>String</tt>)</span>
305
+
306
+
307
+
308
+ &mdash;
309
+ <div class='inline'>
310
+ <p>The directory where output files should be stored.</p>
311
+ </div>
312
+
313
+ </li>
314
+
315
+ </ul>
316
+
317
+
318
+ </div><table class="source_code">
319
+ <tr>
320
+ <td>
321
+ <pre class="lines">
322
+
323
+
324
+ 101
325
+ 102
326
+ 103
327
+ 104
328
+ 105
329
+ 106
330
+ 107
331
+ 108
332
+ 109
333
+ 110
334
+ 111
335
+ 112
336
+ 113
337
+ 114
338
+ 115
339
+ 116
340
+ 117
341
+ 118
342
+ 119
343
+ 120
344
+ 121
345
+ 122
346
+ 123
347
+ 124
348
+ 125
349
+ 126
350
+ 127
351
+ 128</pre>
352
+ </td>
353
+ <td>
354
+ <pre class="code"><span class="info file"># File 'modsulator.rb', line 101</span>
355
+
356
+ <span class='kw'>def</span> <span class='id identifier rubyid_generate_normalized_mods'>generate_normalized_mods</span><span class='lparen'>(</span><span class='id identifier rubyid_template_filename'>template_filename</span><span class='comma'>,</span> <span class='id identifier rubyid_spreadsheet_filename'>spreadsheet_filename</span><span class='comma'>,</span> <span class='id identifier rubyid_output_directory'>output_directory</span><span class='rparen'>)</span>
357
+
358
+ <span class='id identifier rubyid_spreadsheet_rows'>spreadsheet_rows</span> <span class='op'>=</span> <span class='id identifier rubyid_load_spreadsheet'>load_spreadsheet</span><span class='lparen'>(</span><span class='id identifier rubyid_spreadsheet_filename'>spreadsheet_filename</span><span class='rparen'>)</span>
359
+ <span class='id identifier rubyid_mods_template_xml'>mods_template_xml</span> <span class='op'>=</span> <span class='const'>IO</span><span class='period'>.</span><span class='id identifier rubyid_read'>read</span><span class='lparen'>(</span><span class='id identifier rubyid_template_filename'>template_filename</span><span class='rparen'>)</span>
360
+ <span class='id identifier rubyid_invalid_headers'>invalid_headers</span> <span class='op'>=</span> <span class='id identifier rubyid_validate_headers'>validate_headers</span><span class='lparen'>(</span><span class='id identifier rubyid_spreadsheet_rows'>spreadsheet_rows</span><span class='lbracket'>[</span><span class='int'>0</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_keys'>keys</span><span class='comma'>,</span> <span class='id identifier rubyid_mods_template_xml'>mods_template_xml</span><span class='rparen'>)</span>
361
+
362
+ <span class='comment'># To do: generate a warning if there are invalid headers
363
+ </span>
364
+ <span class='comment'># Write one XML file per data row in the input spreadsheet
365
+ </span> <span class='lparen'>(</span><span class='int'>0</span><span class='op'>..</span><span class='lparen'>(</span><span class='id identifier rubyid_spreadsheet_rows'>spreadsheet_rows</span><span class='period'>.</span><span class='id identifier rubyid_length'>length</span><span class='op'>-</span><span class='int'>1</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_i'>i</span><span class='op'>|</span>
366
+ <span class='id identifier rubyid_sourceid'>sourceid</span> <span class='op'>=</span> <span class='id identifier rubyid_spreadsheet_rows'>spreadsheet_rows</span><span class='lbracket'>[</span><span class='id identifier rubyid_i'>i</span><span class='rbracket'>]</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>sourceId</span><span class='tstring_end'>&#39;</span></span><span class='rbracket'>]</span>
367
+ <span class='id identifier rubyid_output_filename'>output_filename</span> <span class='op'>=</span> <span class='id identifier rubyid_output_directory'>output_directory</span> <span class='op'>+</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>/</span><span class='tstring_end'>&quot;</span></span> <span class='op'>+</span> <span class='id identifier rubyid_sourceid'>sourceid</span> <span class='op'>+</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>.xml</span><span class='tstring_end'>&quot;</span></span>
368
+
369
+ <span class='comment'># Generate an XML string, then remove any text carried over from the template
370
+ </span> <span class='id identifier rubyid_generated_xml'>generated_xml</span> <span class='op'>=</span> <span class='id identifier rubyid_generate_xml'>generate_xml</span><span class='lparen'>(</span><span class='id identifier rubyid_spreadsheet_rows'>spreadsheet_rows</span><span class='lbracket'>[</span><span class='id identifier rubyid_i'>i</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id identifier rubyid_mods_template_xml'>mods_template_xml</span><span class='comma'>,</span> <span class='id identifier rubyid_i'>i</span><span class='op'>+</span><span class='int'>1</span><span class='rparen'>)</span>
371
+ <span class='id identifier rubyid_generated_xml'>generated_xml</span><span class='period'>.</span><span class='id identifier rubyid_gsub!'>gsub!</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>\[\[[^\]]+\]\]</span><span class='regexp_end'>/</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span>
372
+
373
+ <span class='comment'># Create an XML Document and normalize it
374
+ </span> <span class='id identifier rubyid_xml_doc'>xml_doc</span> <span class='op'>=</span> <span class='const'>Nokogiri</span><span class='op'>::</span><span class='const'>XML</span><span class='lparen'>(</span><span class='id identifier rubyid_generated_xml'>generated_xml</span><span class='rparen'>)</span>
375
+ <span class='id identifier rubyid_root_node'>root_node</span> <span class='op'>=</span> <span class='id identifier rubyid_xml_doc'>xml_doc</span><span class='period'>.</span><span class='id identifier rubyid_root'>root</span>
376
+ <span class='id identifier rubyid_normalizer'>normalizer</span> <span class='op'>=</span> <span class='const'>Normalizer</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
377
+ <span class='id identifier rubyid_normalizer'>normalizer</span><span class='period'>.</span><span class='id identifier rubyid_remove_empty_nodes'>remove_empty_nodes</span><span class='lparen'>(</span><span class='id identifier rubyid_root_node'>root_node</span><span class='rparen'>)</span>
378
+
379
+ <span class='comment'># To do: notify of errors to the resulting XML
380
+ </span>
381
+ <span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_open'>open</span><span class='lparen'>(</span><span class='id identifier rubyid_output_filename'>output_filename</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>w</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_fh'>fh</span><span class='op'>|</span> <span class='id identifier rubyid_fh'>fh</span><span class='period'>.</span><span class='id identifier rubyid_puts'>puts</span><span class='lparen'>(</span><span class='id identifier rubyid_root_node'>root_node</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='rparen'>)</span> <span class='rbrace'>}</span>
382
+ <span class='kw'>end</span>
383
+ <span class='kw'>end</span></pre>
384
+ </td>
385
+ </tr>
386
+ </table>
387
+ </div>
388
+
389
+ <div class="method_details ">
390
+ <h3 class="signature " id="generate_xml-instance_method">
391
+
392
+ - (<tt>Object</tt>) <strong>generate_xml</strong>(mf, template_xml, row_number)
393
+
394
+
395
+
396
+
397
+
398
+ </h3><div class="docstring">
399
+ <div class="discussion">
400
+
401
+ <p>Write XML to file</p>
402
+
403
+
404
+ </div>
405
+ </div>
406
+ <div class="tags">
407
+
408
+
409
+ </div><table class="source_code">
410
+ <tr>
411
+ <td>
412
+ <pre class="lines">
413
+
414
+
415
+ 62
416
+ 63
417
+ 64
418
+ 65
419
+ 66
420
+ 67
421
+ 68
422
+ 69
423
+ 70
424
+ 71
425
+ 72
426
+ 73
427
+ 74
428
+ 75
429
+ 76
430
+ 77
431
+ 78
432
+ 79
433
+ 80
434
+ 81
435
+ 82
436
+ 83
437
+ 84
438
+ 85
439
+ 86
440
+ 87
441
+ 88
442
+ 89
443
+ 90
444
+ 91
445
+ 92
446
+ 93</pre>
447
+ </td>
448
+ <td>
449
+ <pre class="code"><span class="info file"># File 'modsulator.rb', line 62</span>
450
+
451
+ <span class='kw'>def</span> <span class='id identifier rubyid_generate_xml'>generate_xml</span><span class='lparen'>(</span><span class='id identifier rubyid_mf'>mf</span><span class='comma'>,</span> <span class='id identifier rubyid_template_xml'>template_xml</span><span class='comma'>,</span> <span class='id identifier rubyid_row_number'>row_number</span><span class='rparen'>)</span>
452
+ <span class='id identifier rubyid_manifest_row'>manifest_row</span> <span class='op'>=</span> <span class='id identifier rubyid_mf'>mf</span>
453
+ <span class='id identifier rubyid_mods_template_xml'>mods_template_xml</span> <span class='op'>=</span> <span class='id identifier rubyid_template_xml'>template_xml</span>
454
+
455
+ <span class='comment'># XML escape all of the entries in the manifest row so they won&#39;t break the XML
456
+ </span> <span class='id identifier rubyid_manifest_row'>manifest_row</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='lbrace'>{</span><span class='op'>|</span><span class='id identifier rubyid_k'>k</span><span class='comma'>,</span><span class='id identifier rubyid_v'>v</span><span class='op'>|</span> <span class='id identifier rubyid_manifest_row'>manifest_row</span><span class='lbracket'>[</span><span class='id identifier rubyid_k'>k</span><span class='rbracket'>]</span><span class='op'>=</span><span class='const'>Nokogiri</span><span class='op'>::</span><span class='const'>XML</span><span class='op'>::</span><span class='const'>Text</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_v'>v</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='comma'>,</span><span class='const'>Nokogiri</span><span class='op'>::</span><span class='const'>XML</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span> <span class='kw'>if</span> <span class='id identifier rubyid_v'>v</span> <span class='rbrace'>}</span>
457
+
458
+ <span class='comment'># Enable access with symbol or string keys
459
+ </span> <span class='id identifier rubyid_manifest_row'>manifest_row</span> <span class='op'>=</span> <span class='id identifier rubyid_manifest_row'>manifest_row</span><span class='period'>.</span><span class='id identifier rubyid_with_indifferent_access'>with_indifferent_access</span>
460
+
461
+ <span class='comment'># Run the XML template through ERB. This creates a new ERB object from the template XML,
462
+ </span> <span class='comment'># NOT creating a separate thread, and omitting newlines for lines ending with &#39;%&gt;&#39;
463
+ </span> <span class='id identifier rubyid_template'>template</span> <span class='op'>=</span> <span class='const'>ERB</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_mods_template_xml'>mods_template_xml</span><span class='comma'>,</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>&gt;</span><span class='tstring_end'>&#39;</span></span><span class='rparen'>)</span>
464
+
465
+ <span class='comment'># ERB.result() actually computes the template. This just passes the top level binding.
466
+ </span> <span class='id identifier rubyid_descriptive_metadata_xml'>descriptive_metadata_xml</span> <span class='op'>=</span> <span class='id identifier rubyid_template'>template</span><span class='period'>.</span><span class='id identifier rubyid_result'>result</span><span class='lparen'>(</span><span class='id identifier rubyid_binding'>binding</span><span class='rparen'>)</span>
467
+
468
+ <span class='comment'># The manifest_row is a hash, with column names as the key.
469
+ </span> <span class='comment'># In the template, as a convenience we allow users to put specific column placeholders inside
470
+ </span> <span class='comment'># double brackets: &quot;blah [[column_name]] blah&quot;.
471
+ </span> <span class='comment'># Here we replace those placeholders with the corresponding value
472
+ </span> <span class='comment'># from the manifest row.
473
+ </span> <span class='id identifier rubyid_manifest_row'>manifest_row</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_k'>k</span><span class='comma'>,</span><span class='id identifier rubyid_v'>v</span><span class='op'>|</span> <span class='id identifier rubyid_descriptive_metadata_xml'>descriptive_metadata_xml</span><span class='period'>.</span><span class='id identifier rubyid_gsub!'>gsub!</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>[[</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_k'>k</span><span class='embexpr_end'>}</span><span class='tstring_content'>]]</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='id identifier rubyid_v'>v</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='period'>.</span><span class='id identifier rubyid_strip'>strip</span> <span class='rbrace'>}</span>
474
+ <span class='comment'># manifest_row.each do |k,v|
475
+ </span> <span class='comment'># replaced_xml = descriptive_metadata_xml.gsub!(&quot;[[#{k}]]&quot;, v.to_s.strip)
476
+ </span> <span class='comment'># puts(&quot;rx = #{replaced_xml}&quot;)
477
+ </span> <span class='comment'># if(replaced_xml == nil)
478
+ </span> <span class='comment'># puts(&quot;*** Warning: On line #{row_number}, there were no matches for the header #{k} within the master template. Do you have an error in your spreadsheet?&quot;)
479
+ </span> <span class='comment'># end
480
+ </span> <span class='comment'># end
481
+ </span> <span class='kw'>return</span> <span class='id identifier rubyid_descriptive_metadata_xml'>descriptive_metadata_xml</span>
482
+ <span class='kw'>end</span></pre>
483
+ </td>
484
+ </tr>
485
+ </table>
486
+ </div>
487
+
488
+ <div class="method_details ">
489
+ <h3 class="signature " id="load_spreadsheet-instance_method">
490
+
491
+ - (<tt>Object</tt>) <strong>load_spreadsheet</strong>(filename)
492
+
493
+
494
+
495
+
496
+
497
+ </h3><table class="source_code">
498
+ <tr>
499
+ <td>
500
+ <pre class="lines">
501
+
502
+
503
+ 30
504
+ 31
505
+ 32
506
+ 33
507
+ 34
508
+ 35
509
+ 36
510
+ 37
511
+ 38
512
+ 39
513
+ 40
514
+ 41
515
+ 42
516
+ 43
517
+ 44
518
+ 45
519
+ 46</pre>
520
+ </td>
521
+ <td>
522
+ <pre class="code"><span class="info file"># File 'modsulator.rb', line 30</span>
523
+
524
+ <span class='kw'>def</span> <span class='id identifier rubyid_load_spreadsheet'>load_spreadsheet</span><span class='lparen'>(</span><span class='id identifier rubyid_filename'>filename</span><span class='rparen'>)</span>
525
+ <span class='id identifier rubyid_spreadsheet'>spreadsheet</span> <span class='op'>=</span> <span class='id identifier rubyid_open_spreadsheet'>open_spreadsheet</span><span class='lparen'>(</span><span class='id identifier rubyid_filename'>filename</span><span class='rparen'>)</span>
526
+
527
+ <span class='comment'># The MODS spreadsheet starts with a &quot;super header&quot; in the first row, followed by individual
528
+ </span> <span class='comment'># column headers in the second row. The third row is the start of the actual data.
529
+ </span> <span class='id identifier rubyid_header'>header</span> <span class='op'>=</span> <span class='id identifier rubyid_spreadsheet'>spreadsheet</span><span class='period'>.</span><span class='id identifier rubyid_row'>row</span><span class='lparen'>(</span><span class='int'>2</span><span class='rparen'>)</span>
530
+
531
+ <span class='comment'># need to build up an array here and return it
532
+ </span> <span class='id identifier rubyid_rows'>rows</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
533
+
534
+ <span class='lparen'>(</span><span class='int'>3</span><span class='op'>..</span><span class='id identifier rubyid_spreadsheet'>spreadsheet</span><span class='period'>.</span><span class='id identifier rubyid_last_row'>last_row</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_i'>i</span><span class='op'>|</span>
535
+ <span class='id identifier rubyid_row'>row</span> <span class='op'>=</span> <span class='const'>Hash</span><span class='lbracket'>[</span><span class='lbracket'>[</span><span class='id identifier rubyid_header'>header</span><span class='comma'>,</span> <span class='id identifier rubyid_spreadsheet'>spreadsheet</span><span class='period'>.</span><span class='id identifier rubyid_row'>row</span><span class='lparen'>(</span><span class='id identifier rubyid_i'>i</span><span class='rparen'>)</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_transpose'>transpose</span><span class='rbracket'>]</span>
536
+ <span class='id identifier rubyid_rows'>rows</span><span class='period'>.</span><span class='id identifier rubyid_push'>push</span><span class='lparen'>(</span><span class='id identifier rubyid_row'>row</span><span class='rparen'>)</span>
537
+ <span class='kw'>end</span>
538
+
539
+ <span class='kw'>return</span> <span class='id identifier rubyid_rows'>rows</span>
540
+ <span class='kw'>end</span></pre>
541
+ </td>
542
+ </tr>
543
+ </table>
544
+ </div>
545
+
546
+ <div class="method_details ">
547
+ <h3 class="signature " id="open_spreadsheet-instance_method">
548
+
549
+ - (<tt>Object</tt>) <strong>open_spreadsheet</strong>(filename)
550
+
551
+
552
+
553
+
554
+
555
+ </h3><div class="docstring">
556
+ <div class="discussion">
557
+
558
+ <p>Open spreadsheet based on filename extension</p>
559
+
560
+
561
+ </div>
562
+ </div>
563
+ <div class="tags">
564
+
565
+
566
+ </div><table class="source_code">
567
+ <tr>
568
+ <td>
569
+ <pre class="lines">
570
+
571
+
572
+ 50
573
+ 51
574
+ 52
575
+ 53
576
+ 54
577
+ 55
578
+ 56
579
+ 57</pre>
580
+ </td>
581
+ <td>
582
+ <pre class="code"><span class="info file"># File 'modsulator.rb', line 50</span>
583
+
584
+ <span class='kw'>def</span> <span class='id identifier rubyid_open_spreadsheet'>open_spreadsheet</span><span class='lparen'>(</span><span class='id identifier rubyid_filename'>filename</span><span class='rparen'>)</span>
585
+ <span class='kw'>case</span> <span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_extname'>extname</span><span class='lparen'>(</span><span class='id identifier rubyid_filename'>filename</span><span class='rparen'>)</span>
586
+ <span class='kw'>when</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>.csv</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>then</span> <span class='const'>Roo</span><span class='op'>::</span><span class='const'>CSV</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_filename'>filename</span><span class='rparen'>)</span>
587
+ <span class='kw'>when</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>.xls</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>then</span> <span class='const'>Roo</span><span class='op'>::</span><span class='const'>Excel</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_filename'>filename</span><span class='rparen'>)</span>
588
+ <span class='kw'>when</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>.xlsx</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>then</span> <span class='const'>Roo</span><span class='op'>::</span><span class='const'>Excelx</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_filename'>filename</span><span class='rparen'>)</span>
589
+ <span class='kw'>else</span> <span class='id identifier rubyid_raise'>raise</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Unknown file type: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_filename'>filename</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span>
590
+ <span class='kw'>end</span>
591
+ <span class='kw'>end</span></pre>
592
+ </td>
593
+ </tr>
594
+ </table>
595
+ </div>
596
+
597
+ <div class="method_details ">
598
+ <h3 class="signature " id="validate_headers-instance_method">
599
+
600
+ - (<tt>Array&lt;String&gt;</tt>) <strong>validate_headers</strong>(spreadsheet_headers, template_xml)
601
+
602
+
603
+
604
+
605
+
606
+ </h3><div class="docstring">
607
+ <div class="discussion">
608
+
609
+ <p>Checks that all the headers in the spreadsheet has a corresponding entry in
610
+ the XML template.</p>
611
+
612
+
613
+ </div>
614
+ </div>
615
+ <div class="tags">
616
+ <p class="tag_title">Parameters:</p>
617
+ <ul class="param">
618
+
619
+ <li>
620
+
621
+ <span class='name'>spreadsheet_headers</span>
622
+
623
+
624
+ <span class='type'>(<tt>Array&lt;String&gt;</tt>)</span>
625
+
626
+
627
+
628
+ &mdash;
629
+ <div class='inline'>
630
+ <p>A list of all the headers in the spreadsheet</p>
631
+ </div>
632
+
633
+ </li>
634
+
635
+ <li>
636
+
637
+ <span class='name'>template_xml</span>
638
+
639
+
640
+ <span class='type'>(<tt>String</tt>)</span>
641
+
642
+
643
+
644
+ &mdash;
645
+ <div class='inline'>
646
+ <p>The XML template in a single string</p>
647
+ </div>
648
+
649
+ </li>
650
+
651
+ </ul>
652
+
653
+ <p class="tag_title">Returns:</p>
654
+ <ul class="return">
655
+
656
+ <li>
657
+
658
+
659
+ <span class='type'>(<tt>Array&lt;String&gt;</tt>)</span>
660
+
661
+
662
+
663
+ &mdash;
664
+ <div class='inline'>
665
+ <p>A list of spreadsheet headers that did not appear in the XML template. This
666
+ list will be empty if all the headers were present.</p>
667
+ </div>
668
+
669
+ </li>
670
+
671
+ </ul>
672
+
673
+ </div><table class="source_code">
674
+ <tr>
675
+ <td>
676
+ <pre class="lines">
677
+
678
+
679
+ 137
680
+ 138
681
+ 139
682
+ 140
683
+ 141
684
+ 142
685
+ 143
686
+ 144
687
+ 145
688
+ 146
689
+ 147
690
+ 148
691
+ 149</pre>
692
+ </td>
693
+ <td>
694
+ <pre class="code"><span class="info file"># File 'modsulator.rb', line 137</span>
695
+
696
+ <span class='kw'>def</span> <span class='id identifier rubyid_validate_headers'>validate_headers</span><span class='lparen'>(</span><span class='id identifier rubyid_spreadsheet_headers'>spreadsheet_headers</span><span class='comma'>,</span> <span class='id identifier rubyid_template_xml'>template_xml</span><span class='rparen'>)</span>
697
+ <span class='id identifier rubyid_missing_headers'>missing_headers</span> <span class='op'>=</span> <span class='const'>Array</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
698
+
699
+ <span class='id identifier rubyid_spreadsheet_headers'>spreadsheet_headers</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_header'>header</span><span class='op'>|</span>
700
+ <span class='kw'>if</span><span class='lparen'>(</span><span class='lparen'>(</span><span class='id identifier rubyid_header'>header</span> <span class='op'>!=</span> <span class='kw'>nil</span><span class='rparen'>)</span> <span class='op'>&amp;&amp;</span>
701
+ <span class='op'>!</span><span class='lparen'>(</span><span class='id identifier rubyid_header'>header</span> <span class='op'>==</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>sourceId</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span> <span class='op'>&amp;&amp;</span>
702
+ <span class='op'>!</span><span class='lparen'>(</span><span class='id identifier rubyid_template_xml'>template_xml</span><span class='period'>.</span><span class='id identifier rubyid_include?'>include?</span> <span class='id identifier rubyid_header'>header</span><span class='rparen'>)</span><span class='rparen'>)</span>
703
+ <span class='id identifier rubyid_missing_headers'>missing_headers</span><span class='period'>.</span><span class='id identifier rubyid_push'>push</span><span class='lparen'>(</span><span class='id identifier rubyid_header'>header</span><span class='rparen'>)</span>
704
+ <span class='kw'>end</span>
705
+ <span class='kw'>end</span>
706
+
707
+ <span class='kw'>return</span> <span class='id identifier rubyid_missing_headers'>missing_headers</span>
708
+ <span class='kw'>end</span></pre>
709
+ </td>
710
+ </tr>
711
+ </table>
712
+ </div>
713
+
714
+ </div>
715
+
716
+ </div>
717
+
718
+ <div id="footer">
719
+ Generated on Fri Mar 13 17:20:28 2015 by
720
+ <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
721
+ 0.8.7.6 (ruby-2.2.0).
722
+ </div>
723
+
724
+ </body>
725
+ </html>