modsulator 1.2.1 → 1.3.0

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
  SHA256:
3
- metadata.gz: c5af187c29cf96186367fab9a9f75c932e776d6202164070a95817d8f5a3d987
4
- data.tar.gz: 608dedfc1371255db1093ffd2608c9940cdd2b1ac5d8a71cc0876f187348df18
3
+ metadata.gz: d919f061e61679be249145800d5854f129164a995ec0f4e24de12b65af323d8e
4
+ data.tar.gz: dfee74e48ac27d66ae748eff40b38cc3af99ced8530fadc17194a04ccb93ab00
5
5
  SHA512:
6
- metadata.gz: 14bb22490d92e8a820b313fd7b871ba42afaa0fefe1e382d54779de96bd0dc447f18a346965b79ada71461df3938f0fe28bfafec6a4b8053bbeadbbc95e26d32
7
- data.tar.gz: e4da22da18507215284a4186f563816457af73904eeff25f406fb30f2885a9231ffb4df5377a08fc830473eb4a78aab8bad3b26d7dcc89bcca923c66a65b8828
6
+ metadata.gz: 4113eeba77103b91e02f76266d3e98c200edc5b38561c5961eda60658c9bb639fac8fa84763c5985faeecacca61178212890c092168d290c744aab0b02541591
7
+ data.tar.gz: dc5de2130ca399902ad086a55e8a510490cdc5643333e563396be84c8f20f54a5a4711d010ff3ee571ed4122d0414954bca8ebf8d397962c01a8e917adbc84c8
@@ -26,9 +26,8 @@ class ModsulatorSheet
26
26
  # the spreadsheet headers.
27
27
  def rows
28
28
  # Parse the spreadsheet, automatically finding the header row by looking for "druid" and "sourceId" and leave the
29
- # header row itself out of the resulting array. Everything preceding the header row is discarded. Would like to use
30
- # clean: true here, but the latest release of Roo 1.13.2 crashes. 2.0.0beta1 seems to work though.
31
- @rows ||= spreadsheet.parse(header_search: ['druid', 'sourceId']).drop(1)
29
+ # header row itself out of the resulting array. Everything preceding the header row is discarded.
30
+ @rows ||= spreadsheet.parse(header_search: ['druid', 'sourceId'], clean: true)
32
31
  end
33
32
 
34
33
 
@@ -24,6 +24,7 @@ RSpec.describe Modsulator do
24
24
  'location_url.xlsx' => 'location_url.xml',
25
25
  'point_coord_test.xlsx' => 'point_coord_test.xml'
26
26
  }.each do |testfile, results_file|
27
+ puts '.'
27
28
  generated_xml_string = Modsulator.new(File.join(FIXTURES_DIR, testfile), testfile).convert_rows()
28
29
  it "converts #{testfile} to valid XML" do
29
30
  error_list = Validator.new(File.expand_path("lib/modsulator/modsulator.xsd")).validate_xml_string(generated_xml_string)
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: modsulator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tommy Ingulfsen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-12 00:00:00.000000000 Z
11
+ date: 2018-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: roo
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 2.5.1
19
+ version: 2.7.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 2.5.1
26
+ version: 2.7.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: equivalent-xml
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -175,20 +175,6 @@ files:
175
175
  - README.md
176
176
  - Rakefile
177
177
  - bin/modsulator
178
- - lib/doc/Modsulator.html
179
- - lib/doc/_index.html
180
- - lib/doc/class_list.html
181
- - lib/doc/css/common.css
182
- - lib/doc/css/full_list.css
183
- - lib/doc/css/style.css
184
- - lib/doc/file_list.html
185
- - lib/doc/frames.html
186
- - lib/doc/index.html
187
- - lib/doc/js/app.js
188
- - lib/doc/js/full_list.js
189
- - lib/doc/js/jquery.js
190
- - lib/doc/method_list.html
191
- - lib/doc/top-level-namespace.html
192
178
  - lib/modsulator.rb
193
179
  - lib/modsulator/mods-3-6.xsd
194
180
  - lib/modsulator/modsulator.xsd
@@ -274,66 +260,66 @@ required_rubygems_version: !ruby/object:Gem::Requirement
274
260
  version: '0'
275
261
  requirements: []
276
262
  rubyforge_project:
277
- rubygems_version: 2.7.3
263
+ rubygems_version: 2.7.6
278
264
  signing_key:
279
265
  specification_version: 4
280
266
  summary: Produces (Stanford) MODS XML from spreadsheets.
281
267
  test_files:
268
+ - spec/spec_helper.rb
269
+ - spec/integration_tests/integration_spec.rb
270
+ - spec/features/validator_unit_spec.rb
282
271
  - spec/features/modsulator_sheet_unit_spec.rb
283
272
  - spec/features/process_template_spec.rb
284
- - spec/features/validator_unit_spec.rb
285
- - spec/fixtures/36_ars0056_manifest.xml
286
- - spec/fixtures/36_crowdsourcing_bridget_1.xml
287
- - spec/fixtures/36_crowdsourcing_bridget_2.xml
273
+ - spec/lib/modsulator_spec.rb
288
274
  - spec/fixtures/36_edition_physLoc_intmediatype.xml
289
- - spec/fixtures/36_filled_template_20160711.xml
275
+ - spec/fixtures/filled_template_20160711.xlsx
290
276
  - spec/fixtures/36_Fitch_Chavez.xml
277
+ - spec/fixtures/SC1049_metadata.xlsx
278
+ - spec/fixtures/filled_template_20160711.xml
279
+ - spec/fixtures/crowdsourcing_bridget_2.xlsx
280
+ - spec/fixtures/36_roman_coins_mods.xml
281
+ - spec/fixtures/SC1049_metadata.xml
282
+ - spec/fixtures/36_PosadaSpreadsheet.xml
283
+ - spec/fixtures/Matter_manifest.csv
284
+ - spec/fixtures/Fitch_Chavez.xlsx
285
+ - spec/fixtures/crowdsourcing_bridget_2.xml
286
+ - spec/fixtures/36_Matter_manifest.xml
287
+ - spec/fixtures/Fitch_King.xlsx
288
+ - spec/fixtures/36_filled_template_20160711.xml
289
+ - spec/fixtures/manifest_v0174.csv
290
+ - spec/fixtures/crowdsourcing_bridget_1.xml
291
+ - spec/fixtures/M1463_AV_manifest.xml
292
+ - spec/fixtures/roman_coins_mods.xlsx
291
293
  - spec/fixtures/36_Fitch_King.xml
292
- - spec/fixtures/36_Heckrotte_ChartsOfCoastSurvey.xml
294
+ - spec/fixtures/Fitch_Chavez.xml
295
+ - spec/fixtures/36_point_coord_test.xml
296
+ - spec/fixtures/ars0056_manifest.xml
297
+ - spec/fixtures/invalid_crowdsourcing_bridget_1.xml
298
+ - spec/fixtures/Fitch_King.xml
299
+ - spec/fixtures/M1463_AV_manifest.xlsx
300
+ - spec/fixtures/location_url.xml
293
301
  - spec/fixtures/36_invalid_crowdsourcing_bridget_1.xml
294
- - spec/fixtures/36_location_url.xml
295
- - spec/fixtures/36_M1463_AV_manifest.xml
296
302
  - spec/fixtures/36_manifest_v0174.xml
297
- - spec/fixtures/36_Matter_manifest.xml
298
- - spec/fixtures/36_point_coord_test.xml
299
- - spec/fixtures/36_PosadaSpreadsheet.xml
300
- - spec/fixtures/36_roman_coins_mods.xml
301
- - spec/fixtures/36_SC1049_metadata.xml
303
+ - spec/fixtures/roman_coins_mods.xml
304
+ - spec/fixtures/edition_physLoc_intmediatype.xml
305
+ - spec/fixtures/PosadaSpreadsheet.xlsx
306
+ - spec/fixtures/Heckrotte_ChartsOfCoastSurvey.xml
302
307
  - spec/fixtures/ars0056_manifest.csv
303
- - spec/fixtures/ars0056_manifest.xml
304
- - spec/fixtures/crowdsourcing_bridget_1.xlsx
305
- - spec/fixtures/crowdsourcing_bridget_1.xml
306
- - spec/fixtures/crowdsourcing_bridget_2.xlsx
307
- - spec/fixtures/crowdsourcing_bridget_2.xml
308
308
  - spec/fixtures/edition_physLoc_intmediatype.xlsx
309
- - spec/fixtures/edition_physLoc_intmediatype.xml
310
- - spec/fixtures/filled_template_20160711.xlsx
311
- - spec/fixtures/filled_template_20160711.xml
312
- - spec/fixtures/Fitch_Chavez.xlsx
313
- - spec/fixtures/Fitch_Chavez.xml
314
- - spec/fixtures/Fitch_King.xlsx
315
- - spec/fixtures/Fitch_King.xml
309
+ - spec/fixtures/36_Heckrotte_ChartsOfCoastSurvey.xml
310
+ - spec/fixtures/36_location_url.xml
311
+ - spec/fixtures/36_crowdsourcing_bridget_1.xml
316
312
  - spec/fixtures/Heckrotte_ChartsOfCoastSurvey.xlsx
317
- - spec/fixtures/Heckrotte_ChartsOfCoastSurvey.xml
318
- - spec/fixtures/invalid_crowdsourcing_bridget_1.xml
313
+ - spec/fixtures/36_SC1049_metadata.xml
319
314
  - spec/fixtures/location_url.xlsx
320
- - spec/fixtures/location_url.xml
321
- - spec/fixtures/M1463_AV_manifest.xlsx
322
- - spec/fixtures/M1463_AV_manifest.xml
323
- - spec/fixtures/manifest_v0174.csv
315
+ - spec/fixtures/36_crowdsourcing_bridget_2.xml
316
+ - spec/fixtures/PosadaSpreadsheet.xml
317
+ - spec/fixtures/point_coord_test.xml
318
+ - spec/fixtures/36_ars0056_manifest.xml
319
+ - spec/fixtures/test_002.xlsx
320
+ - spec/fixtures/test_002.csv
324
321
  - spec/fixtures/manifest_v0174.xml
325
- - spec/fixtures/Matter_manifest.csv
322
+ - spec/fixtures/36_M1463_AV_manifest.xml
326
323
  - spec/fixtures/Matter_manifest.xml
324
+ - spec/fixtures/crowdsourcing_bridget_1.xlsx
327
325
  - spec/fixtures/point_coord_test.xlsx
328
- - spec/fixtures/point_coord_test.xml
329
- - spec/fixtures/PosadaSpreadsheet.xlsx
330
- - spec/fixtures/PosadaSpreadsheet.xml
331
- - spec/fixtures/roman_coins_mods.xlsx
332
- - spec/fixtures/roman_coins_mods.xml
333
- - spec/fixtures/SC1049_metadata.xlsx
334
- - spec/fixtures/SC1049_metadata.xml
335
- - spec/fixtures/test_002.csv
336
- - spec/fixtures/test_002.xlsx
337
- - spec/integration_tests/integration_spec.rb
338
- - spec/lib/modsulator_spec.rb
339
- - spec/spec_helper.rb
@@ -1,725 +0,0 @@
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>