stanford-mods 2.6.4 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +1 -1
  3. data/lib/stanford-mods/{geo_spatial.rb → concerns/geo_spatial.rb} +3 -5
  4. data/lib/stanford-mods/concerns/name.rb +57 -0
  5. data/lib/stanford-mods/concerns/origin_info.rb +113 -0
  6. data/lib/stanford-mods/{physical_location.rb → concerns/physical_location.rb} +2 -2
  7. data/lib/stanford-mods/concerns/searchworks.rb +125 -0
  8. data/lib/stanford-mods/concerns/searchworks_subjects.rb +126 -0
  9. data/lib/stanford-mods/concerns/title.rb +87 -0
  10. data/lib/stanford-mods/coordinate.rb +24 -3
  11. data/lib/stanford-mods/date_parsing.rb +32 -289
  12. data/lib/stanford-mods/imprint.rb +170 -322
  13. data/lib/stanford-mods/record.rb +20 -0
  14. data/lib/stanford-mods/version.rb +1 -1
  15. data/lib/stanford-mods/{searchworks_languages.rb → vocabularies/searchworks_languages.rb} +0 -0
  16. data/lib/stanford-mods.rb +12 -11
  17. data/spec/fixtures/searchworks_imprint_data.rb +38 -39
  18. data/spec/fixtures/searchworks_pub_date_data.rb +7 -7
  19. data/spec/fixtures/spotlight_pub_date_data.rb +7 -7
  20. data/spec/geo_spatial_spec.rb +1 -6
  21. data/spec/imprint_spec.rb +263 -207
  22. data/spec/lib/stanford-mods/coordinate_spec.rb +3 -5
  23. data/spec/name_spec.rb +26 -230
  24. data/spec/origin_info_spec.rb +34 -300
  25. data/spec/searchworks_basic_spec.rb +1 -3
  26. data/spec/searchworks_pub_dates_spec.rb +0 -215
  27. data/spec/searchworks_spec.rb +0 -21
  28. data/spec/searchworks_subject_raw_spec.rb +106 -105
  29. data/spec/searchworks_subject_spec.rb +19 -55
  30. data/spec/searchworks_title_spec.rb +5 -5
  31. data/stanford-mods.gemspec +1 -1
  32. metadata +19 -15
  33. data/lib/marc_countries.rb +0 -387
  34. data/lib/stanford-mods/geo_utils.rb +0 -28
  35. data/lib/stanford-mods/name.rb +0 -80
  36. data/lib/stanford-mods/origin_info.rb +0 -489
  37. data/lib/stanford-mods/searchworks.rb +0 -333
  38. data/lib/stanford-mods/searchworks_subjects.rb +0 -196
  39. data/spec/date_parsing_spec.rb +0 -905
@@ -31,8 +31,8 @@ describe "computations from /originInfo field" do
31
31
  '<dateCreated point="end">1599</dateCreated>' +
32
32
  mods_origin_info_end_str
33
33
  smods_rec.from_str(mods_str)
34
- expect(smods_rec.send(method_sym, true)).to eq method_sym.to_s =~ /int/ ? 1599 : '1599'
35
- expect(smods_rec.send(method_sym, false)).to eq method_sym.to_s =~ /int/ ? 1000 : '1000'
34
+ expect(smods_rec.send(method_sym, ignore_approximate: true)).to eq method_sym.to_s =~ /int/ ? 1599 : '1599'
35
+ expect(smods_rec.send(method_sym, ignore_approximate: false)).to eq method_sym.to_s =~ /int/ ? 1000 : '1000'
36
36
  end
37
37
  it 'nil if ignore_approximate and all dates are approximate' do
38
38
  mods_str = mods_origin_info_start_str +
@@ -40,8 +40,8 @@ describe "computations from /originInfo field" do
40
40
  '<dateCreated point="end" qualifier="questionable">1599</dateCreated>' +
41
41
  mods_origin_info_end_str
42
42
  smods_rec.from_str(mods_str)
43
- expect(smods_rec.send(method_sym, true)).to eq nil
44
- expect(smods_rec.send(method_sym, false)).to eq method_sym.to_s =~ /int/ ? 1000 : '1000'
43
+ expect(smods_rec.send(method_sym, ignore_approximate: true)).to eq nil
44
+ expect(smods_rec.send(method_sym, ignore_approximate: false)).to eq method_sym.to_s =~ /int/ ? 1000 : '1000'
45
45
  end
46
46
  it 'respects ignore_approximate even for keyDate' do
47
47
  mods_str = mods_origin_info_start_str +
@@ -49,14 +49,14 @@ describe "computations from /originInfo field" do
49
49
  '<dateCreated point="end">1599</dateCreated>' +
50
50
  mods_origin_info_end_str
51
51
  smods_rec.from_str(mods_str)
52
- expect(smods_rec.send(method_sym, true)).to eq method_sym.to_s =~ /int/ ? 1599 : '1599'
53
- expect(smods_rec.send(method_sym, false)).to eq method_sym.to_s =~ /int/ ? 1000 : '1000'
52
+ expect(smods_rec.send(method_sym, ignore_approximate: true)).to eq method_sym.to_s =~ /int/ ? 1599 : '1599'
53
+ expect(smods_rec.send(method_sym, ignore_approximate: false)).to eq method_sym.to_s =~ /int/ ? 1000 : '1000'
54
54
  end
55
55
  it 'uses dateCaptured if no dateIssued or dateCreated' do
56
56
  # for web archive seed files
57
57
  mods_str = mods_origin_info_start_str +
58
- '<dateCaptured encoding="w3cdtf" point="start" keyDate="yes">20151215121212</dateCaptured>' +
59
- '<dateCaptured encoding="w3cdtf" point="end">20151218111111</dateCaptured>' +
58
+ '<dateCaptured encoding="iso8601" point="start" keyDate="yes">20151215121212</dateCaptured>' +
59
+ '<dateCaptured encoding="iso8601" point="end">20151218111111</dateCaptured>' +
60
60
  mods_origin_info_end_str
61
61
  smods_rec.from_str(mods_str)
62
62
  expect(smods_rec.send(method_sym)).to eq method_sym.to_s =~ /int/ ? 2015 : '2015'
@@ -92,24 +92,24 @@ describe "computations from /originInfo field" do
92
92
  it '-200 for 200 B.C.' do
93
93
  # hd778hw9236
94
94
  mods_str = mods_origin_info_start_str +
95
- '<dateCreated encoding="w3cdtf" keyDate="yes" point="start" qualifier="approximate">200 B.C.</dateCreated>' +
96
- '<dateCreated encoding="w3cdtf" keyDate="yes" point="end" qualifier="approximate">180 B.C.</dateCreated>' +
95
+ '<dateCreated keyDate="yes" point="start" qualifier="approximate">200 B.C.</dateCreated>' +
96
+ '<dateCreated keyDate="yes" point="end" qualifier="approximate">180 B.C.</dateCreated>' +
97
97
  mods_origin_info_end_str
98
98
  smods_rec.from_str(mods_str)
99
- expect(smods_rec.pub_year_int).to eq(-200)
99
+ expect(smods_rec.pub_year_int).to eq(-199)
100
100
  end
101
101
  it '-211 for 211 B.C.' do
102
102
  # ww728rz0477
103
103
  mods_str = mods_origin_info_start_str +
104
- '<dateCreated encoding="w3cdtf" keyDate="yes" point="start" qualifier="approximate">211 B.C.</dateCreated>' +
105
- '<dateCreated encoding="w3cdtf" keyDate="yes" point="end" qualifier="approximate">150 B.C.</dateCreated>' +
104
+ '<dateCreated keyDate="yes" point="start" qualifier="approximate">211 B.C.</dateCreated>' +
105
+ '<dateCreated keyDate="yes" point="end" qualifier="approximate">150 B.C.</dateCreated>' +
106
106
  mods_origin_info_end_str
107
107
  smods_rec.from_str(mods_str)
108
- expect(smods_rec.pub_year_int).to eq(-211)
108
+ expect(smods_rec.pub_year_int).to eq(-210)
109
109
  end
110
110
  end
111
111
 
112
- context '*earliest_year_str' do
112
+ context '*best_or_earliest_year' do
113
113
  it 'selects earliest (valid) parseable date from multiple options' do
114
114
  mods_str = mods_origin_info_start_str +
115
115
  '<dateIssued point="start" qualifier="questionable">1758</dateIssued>' +
@@ -117,7 +117,7 @@ describe "computations from /originInfo field" do
117
117
  '<dateIssued>1753]</dateIssued>' +
118
118
  mods_origin_info_end_str
119
119
  smods_rec.from_str(mods_str)
120
- expect(Stanford::Mods::Record.earliest_year_str(smods_rec.date_issued_elements)).to eq ['1753', '1753]']
120
+ expect(Stanford::Mods::OriginInfo.best_or_earliest_year(smods_rec.origin_info.dateIssued).xml.text).to eq '1753]'
121
121
  end
122
122
  it 'ignores encoding' do
123
123
  # encoding matters for choosing display, not for parsing year
@@ -127,31 +127,21 @@ describe "computations from /originInfo field" do
127
127
  '<dateIssued encoding="w3cdtf">1300</dateIssued>' +
128
128
  mods_origin_info_end_str
129
129
  smods_rec.from_str(mods_str)
130
- expect(Stanford::Mods::Record.earliest_year_str(smods_rec.date_issued_elements)).to eq ['1100', '1100']
130
+ expect(Stanford::Mods::OriginInfo.best_or_earliest_year(smods_rec.origin_info.dateIssued).xml.text).to eq '1100'
131
131
  mods_str = mods_origin_info_start_str +
132
132
  '<dateIssued>1200</dateIssued>' +
133
133
  '<dateIssued encoding="marc">1300</dateIssued>' +
134
134
  '<dateIssued encoding="w3cdtf">1100</dateIssued>' +
135
135
  mods_origin_info_end_str
136
136
  smods_rec.from_str(mods_str)
137
- expect(Stanford::Mods::Record.earliest_year_str(smods_rec.date_issued_elements)).to eq ['1100', '1100']
137
+ expect(Stanford::Mods::OriginInfo.best_or_earliest_year(smods_rec.origin_info.dateIssued).xml.text).to eq '1100'
138
138
  mods_str = mods_origin_info_start_str +
139
139
  '<dateIssued>1300</dateIssued>' +
140
140
  '<dateIssued encoding="marc">1100</dateIssued>' +
141
141
  '<dateIssued encoding="w3cdtf">1200</dateIssued>' +
142
142
  mods_origin_info_end_str
143
143
  smods_rec.from_str(mods_str)
144
- expect(Stanford::Mods::Record.earliest_year_str(smods_rec.date_issued_elements)).to eq ['1100', '1100']
145
- end
146
- it 'calls DateParsing.sortable_year_string_from_date_str for each element value' do
147
- mods_str = mods_origin_info_start_str +
148
- '<dateIssued>1100</dateIssued>' +
149
- '<dateIssued encoding="marc">1200</dateIssued>' +
150
- '<dateIssued encoding="w3cdtf">1300</dateIssued>' +
151
- mods_origin_info_end_str
152
- smods_rec.from_str(mods_str)
153
- expect(Stanford::Mods::DateParsing).to receive(:sortable_year_string_from_date_str).exactly(3).times
154
- Stanford::Mods::Record.earliest_year_str(smods_rec.date_issued_elements)
144
+ expect(Stanford::Mods::OriginInfo.best_or_earliest_year(smods_rec.origin_info.dateIssued).xml.text).to eq '1100'
155
145
  end
156
146
  end
157
147
 
@@ -162,7 +152,7 @@ describe "computations from /originInfo field" do
162
152
  '<dateIssued keyDate="yes">2014</dateIssued>' +
163
153
  mods_origin_info_end_str
164
154
  smods_rec.from_str(mods_str)
165
- expect(smods_rec.send(method_sym, smods_rec.date_issued_elements)).to eq method_sym.to_s =~ /int/ ? 2014 : '2014'
155
+ expect(smods_rec.send(method_sym, smods_rec.origin_info.dateIssued)).to eq method_sym.to_s =~ /int/ ? 2014 : '2014'
166
156
  end
167
157
  it 'ignores invalid keyDate value' do
168
158
  mods_str = mods_origin_info_start_str +
@@ -170,22 +160,18 @@ describe "computations from /originInfo field" do
170
160
  '<dateIssued>1499</dateIssued>' +
171
161
  mods_origin_info_end_str
172
162
  smods_rec.from_str(mods_str)
173
- expect(smods_rec.send(method_sym, smods_rec.date_issued_elements)).to eq method_sym.to_s =~ /int/ ? 1499 : '1499'
163
+ expect(smods_rec.send(method_sym, smods_rec.origin_info.dateIssued)).to eq method_sym.to_s =~ /int/ ? 1499 : '1499'
174
164
  end
175
- it 'calls earliest_year_str if multiple keyDates present' do
165
+ it 'calls earliest_year if multiple keyDates present' do
176
166
  mods_str = mods_origin_info_start_str +
177
167
  '<dateCreated keyDate="yes">2003</dateCreated>' +
178
168
  '<dateCreated keyDate="yes">2001</dateCreated>' +
179
169
  mods_origin_info_end_str
180
170
  smods_rec.from_str(mods_str)
181
- if method_sym.to_s =~ /int/
182
- expect(Stanford::Mods::Record).to receive(:earliest_year_int).with(smods_rec.date_created_elements)
183
- else
184
- expect(Stanford::Mods::Record).to receive(:earliest_year_str).with(smods_rec.date_created_elements)
185
- end
186
- expect(smods_rec.send(method_sym, smods_rec.date_created_elements))
171
+ expect(Stanford::Mods::OriginInfo).to receive(:best_or_earliest_year).with(smods_rec.origin_info.dateCreated)
172
+ expect(smods_rec.send(method_sym, smods_rec.origin_info.dateCreated))
187
173
  end
188
- it 'calls earliest_year_str if no keyDate' do
174
+ it 'calls earliest_year if no keyDate' do
189
175
  mods_str = mods_origin_info_start_str +
190
176
  '<dateIssued>1753]</dateIssued>' +
191
177
  '<dateIssued point="start" qualifier="questionable">1758</dateIssued>' +
@@ -193,11 +179,11 @@ describe "computations from /originInfo field" do
193
179
  mods_origin_info_end_str
194
180
  smods_rec.from_str(mods_str)
195
181
  if method_sym.to_s =~ /int/
196
- expect(Stanford::Mods::Record).to receive(:earliest_year_int).with(smods_rec.date_issued_elements)
182
+ expect(Stanford::Mods::OriginInfo).to receive(:best_or_earliest_year).with(smods_rec.origin_info.dateIssued)
197
183
  else
198
- expect(Stanford::Mods::Record).to receive(:earliest_year_str).with(smods_rec.date_issued_elements)
184
+ expect(Stanford::Mods::OriginInfo).to receive(:best_or_earliest_year).with(smods_rec.origin_info.dateIssued)
199
185
  end
200
- smods_rec.send(method_sym, smods_rec.date_issued_elements)
186
+ smods_rec.send(method_sym, smods_rec.origin_info.dateIssued)
201
187
  end
202
188
  it 'ignores encoding' do
203
189
  # encoding matters for choosing display, not for parsing year
@@ -207,229 +193,25 @@ describe "computations from /originInfo field" do
207
193
  '<dateIssued encoding="w3cdtf">1300</dateIssued>' +
208
194
  mods_origin_info_end_str
209
195
  smods_rec.from_str(mods_str)
210
- expect(smods_rec.send(method_sym, smods_rec.date_issued_elements)).to eq method_sym.to_s =~ /int/ ? 1100 : '1100'
196
+ expect(smods_rec.send(method_sym, smods_rec.origin_info.dateIssued)).to eq method_sym.to_s =~ /int/ ? 1100 : '1100'
211
197
  mods_str = mods_origin_info_start_str +
212
198
  '<dateIssued>1200</dateIssued>' +
213
199
  '<dateIssued encoding="marc">1300</dateIssued>' +
214
200
  '<dateIssued encoding="w3cdtf" keyDate="yes">1100</dateIssued>' +
215
201
  mods_origin_info_end_str
216
202
  smods_rec.from_str(mods_str)
217
- expect(smods_rec.send(method_sym, smods_rec.date_issued_elements)).to eq method_sym.to_s =~ /int/ ? 1100 : '1100'
203
+ expect(smods_rec.send(method_sym, smods_rec.origin_info.dateIssued)).to eq method_sym.to_s =~ /int/ ? 1100 : '1100'
218
204
  mods_str = mods_origin_info_start_str +
219
205
  '<dateIssued>1300</dateIssued>' +
220
206
  '<dateIssued encoding="marc" keyDate="yes">1100</dateIssued>' +
221
207
  '<dateIssued encoding="w3cdtf">1200</dateIssued>' +
222
208
  mods_origin_info_end_str
223
209
  smods_rec.from_str(mods_str)
224
- expect(smods_rec.send(method_sym, smods_rec.date_issued_elements)).to eq method_sym.to_s =~ /int/ ? 1100 : '1100'
225
- end
226
- end
227
-
228
- context '#year_display_str' do
229
- it_behaves_like "pub date best single value", :year_display_str
230
- it 'uses facet value, not sorting value' do
231
- mods_str = mods_origin_info_start_str +
232
- '<dateCreated keyDate="yes">180 B.C.</dateCreated>' +
233
- mods_origin_info_end_str
234
- smods_rec.from_str(mods_str)
235
- expect(smods_rec.year_display_str(smods_rec.date_created_elements)).to eq '180 B.C.'
236
- end
237
- end
238
-
239
- context '#year_sort_str' do
240
- it_behaves_like "pub date best single value", :year_sort_str
241
- it 'uses string sorting value, not facet value' do
242
- mods_str = mods_origin_info_start_str +
243
- '<dateCreated keyDate="yes">180 B.C.</dateCreated>' +
244
- mods_origin_info_end_str
245
- smods_rec.from_str(mods_str)
246
- expect(smods_rec.year_sort_str(smods_rec.date_created_elements)).to eq '-820'
247
- end
248
- end
249
-
250
- context '#year_int' do
251
- it_behaves_like "pub date best single value", :year_int
252
- it 'uses integer sorting value, not string or facet value' do
253
- mods_str = mods_origin_info_start_str +
254
- '<dateCreated keyDate="yes">180 B.C.</dateCreated>' +
255
- mods_origin_info_end_str
256
- smods_rec.from_str(mods_str)
257
- expect(smods_rec.year_int(smods_rec.date_created_elements)).to eq(-180)
258
- end
259
- end
260
-
261
- context '#date_issued_elements' do
262
- # example string as key, expected num of Elements as value
263
- {
264
- '<dateIssued>[1717]</dateIssued><dateIssued encoding="marc">1717</dateIssued>' => 2,
265
- '<dateIssued encoding="marc" point="start">1552</dateIssued>
266
- <dateIssued encoding="marc" point="end">1575</dateIssued>
267
- </originInfo>
268
- <originInfo>
269
- <dateIssued>1544-1628]</dateIssued>' => 3,
270
- '' => 0
271
- }.each do |example, expected|
272
- describe "for example: #{example}" do
273
- let(:example) { example }
274
- it 'returns Array of Nokogiri Elements matching /originInfo/dateIssued' do
275
- smods_rec.from_str(mods_origin_info)
276
- result = smods_rec.date_issued_elements
277
- expect(result).to be_instance_of(Array)
278
- expect(result.size).to eq expected
279
- expect(result).to all(be_an(Nokogiri::XML::Element))
280
- end
281
- end
282
- end
283
-
284
- context 'ignore_approximate=true' do
285
- let(:qual_date_val) { '1666' }
286
- let(:mods_rec) do
287
- <<-EOF
288
- #{mods_origin_info_start_str}
289
- <dateIssued>2015</dateIssued>
290
- <dateIssued qualifier="#{qual_attr_val}">#{qual_date_val}</dateIssued>
291
- #{mods_origin_info_end_str}
292
- EOF
293
- end
294
-
295
- context "removes element when attribute qualifer=" do
296
- ['approximate', 'questionable'].each do |attr_val|
297
- let(:qual_attr_val) { attr_val }
298
- it attr_val do
299
- smods_rec.from_str mods_rec
300
- result = smods_rec.date_issued_elements(true)
301
- expect(result).to be_instance_of(Array)
302
- expect(result.size).to eq 1
303
- expect(result[0].content).to eq '2015'
304
- end
305
- end
306
- end
307
-
308
- context "retains element when attribute qualifer=" do
309
- ['inferred', 'invalid_attr_val'].each do |attr_val|
310
- let(:qual_attr_val) { attr_val }
311
- it attr_val do
312
- smods_rec.from_str mods_rec
313
- result = smods_rec.date_issued_elements(true)
314
- expect(result).to be_instance_of(Array)
315
- expect(result.size).to eq 2
316
- expect(result[0].content).to eq '2015'
317
- expect(result[1].content).to eq '1666'
318
- end
319
- end
320
- end
321
-
322
- let(:start_str) { "#{mods_origin_info_start_str}<dateIssued>2015</dateIssued>" }
323
- it 'retains element without qualifier attribute"' do
324
- m = start_str + '<dateIssued>1666</dateIssued>' + mods_origin_info_end_str
325
- smods_rec.from_str m
326
- result = smods_rec.date_issued_elements(true)
327
- expect(result).to be_instance_of(Array)
328
- expect(result.size).to eq 2
329
- expect(result[0].content).to eq '2015'
330
- expect(result[1].content).to eq '1666'
331
- end
332
- end
333
- end
334
-
335
- context '#date_created_elements' do
336
- # example string as key, expected num of Elements as value
337
- {
338
- '<dateCreated encoding="edtf" keydate="yes" point="start">-0012</dateCreated>
339
- <dateCreated encoding="edtf" point="end">-0044</dateCreated>' => 2,
340
- '' => 0
341
- }.each do |example, expected|
342
- describe "for example: '#{example}'" do
343
- let(:example) { example }
344
- it 'returns Array of Nokogiri Elements matching /originInfo/dateCreated' do
345
- smods_rec.from_str(mods_origin_info)
346
- result = smods_rec.date_created_elements
347
- expect(result).to be_instance_of(Array)
348
- expect(result.size).to eq expected
349
- expect(result).to all(be_an(Nokogiri::XML::Element))
350
- end
351
- end
352
- end
353
-
354
- context 'ignore_approximate=true' do
355
- let(:qual_date_val) { '1666' }
356
- let(:mods_rec) do
357
- <<-EOF
358
- #{mods_origin_info_start_str}
359
- <dateCreated>2015</dateCreated>
360
- <dateCreated qualifier="#{qual_attr_val}">#{qual_date_val}</dateCreated>
361
- #{mods_origin_info_end_str}
362
- EOF
363
- end
364
-
365
- context "removes element when attribute qualifer=" do
366
- ['approximate', 'questionable'].each do |attr_val|
367
- let(:qual_attr_val) { attr_val }
368
- it attr_val do
369
- smods_rec.from_str mods_rec
370
- result = smods_rec.date_created_elements(true)
371
- expect(result).to be_instance_of(Array)
372
- expect(result.size).to eq 1
373
- expect(result[0].content).to eq '2015'
374
- end
375
- end
376
- end
377
-
378
- context "retains element when attribute qualifer=" do
379
- ['inferred', 'invalid_attr_val'].each do |attr_val|
380
- let(:qual_attr_val) { attr_val }
381
- it attr_val do
382
- smods_rec.from_str mods_rec
383
- result = smods_rec.date_created_elements(true)
384
- expect(result).to be_instance_of(Array)
385
- expect(result.size).to eq 2
386
- expect(result[0].content).to eq '2015'
387
- expect(result[1].content).to eq '1666'
388
- end
389
- end
390
- end
391
-
392
- let(:start_str) { "#{mods_origin_info_start_str}<dateCreated>2015</dateCreated>" }
393
- it 'retains element without qualifier attribute"' do
394
- m = start_str + '<dateCreated>1666</dateCreated>' + mods_origin_info_end_str
395
- smods_rec.from_str m
396
- result = smods_rec.date_created_elements(true)
397
- expect(result).to be_instance_of(Array)
398
- expect(result.size).to eq 2
399
- expect(result[0].content).to eq '2015'
400
- expect(result[1].content).to eq '1666'
401
- end
402
- end
403
- end
404
-
405
- context '*keyDate' do
406
- it 'returns nil if passed Array is empty' do
407
- mods_str = "#{mods_origin_info_start_str}#{mods_origin_info_end_str}"
408
- smods_rec.from_str(mods_str)
409
- expect(Stanford::Mods::Record.keyDate(smods_rec.date_issued_elements)).to be_nil
410
- end
411
- it 'returns nil if passed Array has no element with keyDate attribute' do
412
- mods_str = "#{mods_origin_info_start_str}<dateIssued>[1738]</dateIssued>#{mods_origin_info_end_str}"
413
- smods_rec.from_str(mods_str)
414
- expect(Stanford::Mods::Record.keyDate(smods_rec.date_issued_elements)).to be_nil
415
- end
416
- it 'returns nil if passed Array has multiple elements with keyDate attribute' do
417
- mods_str = "#{mods_origin_info_start_str}
418
- <dateIssued>[1968?-</dateIssued>
419
- <dateIssued encoding='marc' point='start' keyDate='yes'>1968</dateIssued>
420
- <dateIssued encoding='marc' point='end' keyDate='yes'>9999</dateIssued>
421
- #{mods_origin_info_end_str}"
422
- smods_rec.from_str(mods_str)
423
- expect(Stanford::Mods::Record.keyDate(smods_rec.date_issued_elements)).to be_nil
424
- end
425
- it 'returns single Nokogiri::XML::Element if Arrays has single element with keyDate attribute' do
426
- mods_str = "#{mods_origin_info_start_str}<dateIssued encoding='w3cdtf' keyDate='yes'>2011</dateIssued>#{mods_origin_info_end_str}"
427
- smods_rec.from_str(mods_str)
428
- expect(Stanford::Mods::Record.keyDate(smods_rec.date_issued_elements)).to be_instance_of(Nokogiri::XML::Element)
210
+ expect(smods_rec.send(method_sym, smods_rec.origin_info.dateIssued)).to eq method_sym.to_s =~ /int/ ? 1100 : '1100'
429
211
  end
430
212
  end
431
213
 
432
- context '*remove_approximate' do
214
+ context '*is_approximate' do
433
215
  it 'removes elements when date_is_approximate? returns true' do
434
216
  mods_str = "#{mods_origin_info_start_str}
435
217
  <dateIssued>1900</dateIssued>
@@ -437,59 +219,11 @@ describe "computations from /originInfo field" do
437
219
  <dateIssued qualifier='questionable'>1930</dateIssued>
438
220
  #{mods_origin_info_end_str}"
439
221
  smods_rec.from_str(mods_str)
440
- elements = smods_rec.date_issued_elements
222
+ elements = smods_rec.origin_info.dateIssued
441
223
  expect(elements.size).to eq 3
442
- result = Stanford::Mods::Record.remove_approximate(elements)
224
+ result = elements.reject { |n| smods_rec.is_approximate(n) }
443
225
  expect(result).to be_instance_of(Array)
444
226
  expect(result.size).to eq 2
445
- expect(result.select { |date_el| Stanford::Mods::Record.date_is_approximate?(date_el) }).to eq []
446
- end
447
- end
448
-
449
- context '#date_is_approximate?' do
450
- it 'false if bad param passed' do
451
- expect(Stanford::Mods::Record.date_is_approximate?(true)).to eq false
452
- end
453
- it 'false if there is no qualifier attrib' do
454
- mods_str = "#{mods_origin_info_start_str}<dateIssued>1968</dateIssued>#{mods_origin_info_end_str}"
455
- smods_rec.from_str(mods_str)
456
- date_el = smods_rec.date_issued_elements.first
457
- expect(Stanford::Mods::Record.date_is_approximate?(date_el)).to eq false
458
- end
459
- # value of qualifier attribute as key, expected result as value
460
- {
461
- 'approximate' => true,
462
- 'questionable' => true,
463
- 'inferred' => false,
464
- 'typo' => false
465
- }.each do |attr_value, expected|
466
- describe "for qualifier value: '#{attr_value}'" do
467
- let(:mods_str) do
468
- "#{mods_origin_info_start_str}
469
- <dateIssued qualifier='#{attr_value}'>1968</dateIssued>
470
- #{mods_origin_info_end_str}"
471
- end
472
- it expected.to_s do
473
- smods_rec.from_str(mods_str)
474
- date_el = smods_rec.date_issued_elements.first
475
- expect(Stanford::Mods::Record.date_is_approximate?(date_el)).to eq expected
476
- end
477
- end
478
- end
479
- end
480
-
481
- context '#get_u_year' do
482
- it "turns ending u to 0" do
483
- expect(smods_rec.send(:get_u_year, ["201u"])).to eql "2010"
484
- expect(smods_rec.send(:get_u_year, ["198u"])).to eql "1980"
485
- expect(smods_rec.send(:get_u_year, ["185u"])).to eql "1850"
486
- end
487
- it "turns ending uu to --" do
488
- expect(smods_rec.send(:get_u_year, ["19uu"])).to eql "19--"
489
- expect(smods_rec.send(:get_u_year, ["17uu"])).to eql "17--"
490
- end
491
- it 'ignores 9999' do
492
- expect(smods_rec.send(:get_u_year, ["9999"])).to be_nil
493
227
  end
494
228
  end
495
229
  end
@@ -1,6 +1,4 @@
1
- # require 'spec_helper'
2
- # not using spec_helper here: testing require
3
- require 'stanford-mods/searchworks'
1
+ require 'spec_helper'
4
2
 
5
3
  describe 'Basic construction' do
6
4
  before(:each) do