stanford-mods 3.0.0 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,229 +1,581 @@
1
1
  describe "computations from /originInfo field" do
2
- let(:smods_rec) { Stanford::Mods::Record.new }
3
-
4
- # used for single examples
5
- let(:mods_origin_info_start_str) { "<mods xmlns=\"#{Mods::MODS_NS}\"><originInfo>" }
6
- let(:mods_origin_info_end_str) { '</originInfo></mods>' }
7
-
8
- # used for hashes/arrays of examples
9
- let(:mods_origin_info) do
10
- <<-EOF
11
- #{mods_origin_info_start_str}
12
- #{example}
13
- #{mods_origin_info_end_str}
14
- EOF
15
- end
2
+ let(:record) { Stanford::Mods::Record.new.from_str(modsxml) }
3
+
4
+ context '#pub_year_display_str' do
5
+ context 'when it has a dateIssued date' do
6
+ let(:modsxml) do
7
+ <<-EOF
8
+ <mods xmlns="http://www.loc.gov/mods/v3">
9
+ <originInfo>
10
+ <dateIssued>1900</dateIssued>
11
+ </originInfo>
12
+ </mods>
13
+ EOF
14
+ end
15
+
16
+ it 'returns the year from the dateIssued field' do
17
+ expect(record.pub_year_display_str).to eq '1900'
18
+ end
19
+ end
20
+
21
+ context 'when it has a dateCreated date' do
22
+ let(:modsxml) do
23
+ <<-EOF
24
+ <mods xmlns="http://www.loc.gov/mods/v3">
25
+ <originInfo>
26
+ <dateCreated>1800</dateCreated>
27
+ </originInfo>
28
+ </mods>
29
+ EOF
30
+ end
31
+
32
+ it 'returns the year from the dateCreated field' do
33
+ expect(record.pub_year_display_str).to eq '1800'
34
+ end
35
+ end
36
+
37
+ context 'when it has a dateCaptured date' do
38
+ let(:modsxml) do
39
+ <<-EOF
40
+ <mods xmlns="http://www.loc.gov/mods/v3">
41
+ <originInfo>
42
+ <dateCaptured>1700</dateCaptured>
43
+ </originInfo>
44
+ </mods>
45
+ EOF
46
+ end
47
+
48
+ it 'returns the year from the dateCaptured field' do
49
+ expect(record.pub_year_display_str).to eq '1700'
50
+ end
51
+ end
52
+
53
+ context 'when it has multiple types of date fields' do
54
+ let(:modsxml) do
55
+ <<-EOF
56
+ <mods xmlns="http://www.loc.gov/mods/v3">
57
+ <originInfo>
58
+ <dateIssued>1900</dateIssued>
59
+ <dateCreated>1800</dateCreated>
60
+ <dateCaptured>1700</dateCaptured>
61
+ </originInfo>
62
+ </mods>
63
+ EOF
64
+ end
65
+
66
+ it 'returns the year from the dateIssued field' do
67
+ expect(record.pub_year_display_str).to eq '1900'
68
+ end
69
+ end
70
+
71
+ context 'when it has a key date of the same type' do
72
+ let(:modsxml) do
73
+ <<-EOF
74
+ <mods xmlns="http://www.loc.gov/mods/v3">
75
+ <originInfo>
76
+ <dateIssued keyDate="yes">1900</dateIssued>
77
+ <dateIssued>1800</dateIssued>
78
+ </originInfo>
79
+ </mods>
80
+ EOF
81
+ end
82
+
83
+ it 'returns the year from the keyDate field' do
84
+ expect(record.pub_year_display_str).to eq '1900'
85
+ end
86
+ end
87
+
88
+ context 'when it has a key date of a different type' do
89
+ let(:modsxml) do
90
+ <<-EOF
91
+ <mods xmlns="http://www.loc.gov/mods/v3">
92
+ <originInfo>
93
+ <dateCreated keyDate="yes">1900</dateCreated>
94
+ <dateIssued>1800</dateIssued>
95
+ </originInfo>
96
+ </mods>
97
+ EOF
98
+ end
99
+
100
+ it 'returns the year from the preferred field type regardless of the keyDate' do
101
+ expect(record.pub_year_display_str).to eq '1800'
102
+ end
103
+ end
104
+
105
+ context 'when it has multiple dates' do
106
+ let(:modsxml) do
107
+ <<-EOF
108
+ <mods xmlns="http://www.loc.gov/mods/v3">
109
+ <originInfo>
110
+ <dateIssued>1900</dateIssued>
111
+ <dateIssued>1800</dateIssued>
112
+ </originInfo>
113
+ </mods>
114
+ EOF
115
+ end
116
+
117
+ it 'returns the earliest year' do
118
+ expect(record.pub_year_display_str).to eq '1800'
119
+ end
120
+ end
121
+
122
+ context 'when it has multiple originInfo elements' do
123
+ let(:modsxml) do
124
+ <<-EOF
125
+ <mods xmlns="http://www.loc.gov/mods/v3">
126
+ <originInfo>
127
+ <dateIssued>1900</dateIssued>
128
+ </originInfo>
129
+ <originInfo>
130
+ <dateIssued>1800</dateIssued>
131
+ </originInfo>
132
+ </mods>
133
+ EOF
134
+ end
135
+
136
+ it 'returns the earliest year across all the dates' do
137
+ expect(record.pub_year_display_str).to eq '1800'
138
+ end
139
+ end
16
140
 
17
- RSpec.shared_examples "single pub date value" do |method_sym, exp_val_position|
18
- it 'prefers dateIssued to dateCreated' do
19
- mods_str = mods_origin_info_start_str +
20
- '<dateIssued>2005</dateIssued>' +
21
- '</originInfo>' +
22
- '<originInfo>
23
- <dateCreated>1999</dateCreated>' +
24
- mods_origin_info_end_str
25
- smods_rec.from_str(mods_str)
26
- expect(smods_rec.send(method_sym)).to eq method_sym.to_s =~ /int/ ? 2005 : '2005'
27
- end
28
- it 'respects ignore_approximate param' do
29
- mods_str = mods_origin_info_start_str +
30
- '<dateCreated point="start" qualifier="approximate">1000</dateCreated>' +
31
- '<dateCreated point="end">1599</dateCreated>' +
32
- mods_origin_info_end_str
33
- smods_rec.from_str(mods_str)
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
- end
37
- it 'nil if ignore_approximate and all dates are approximate' do
38
- mods_str = mods_origin_info_start_str +
39
- '<dateCreated point="start" qualifier="approximate">1000</dateCreated>' +
40
- '<dateCreated point="end" qualifier="questionable">1599</dateCreated>' +
41
- mods_origin_info_end_str
42
- smods_rec.from_str(mods_str)
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
- end
46
- it 'respects ignore_approximate even for keyDate' do
47
- mods_str = mods_origin_info_start_str +
48
- '<dateCreated point="start" qualifier="approximate" keyDate="yes">1000</dateCreated>' +
49
- '<dateCreated point="end">1599</dateCreated>' +
50
- mods_origin_info_end_str
51
- smods_rec.from_str(mods_str)
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
- end
55
- it 'uses dateCaptured if no dateIssued or dateCreated' do
56
- # for web archive seed files
57
- mods_str = mods_origin_info_start_str +
58
- '<dateCaptured encoding="iso8601" point="start" keyDate="yes">20151215121212</dateCaptured>' +
59
- '<dateCaptured encoding="iso8601" point="end">20151218111111</dateCaptured>' +
60
- mods_origin_info_end_str
61
- smods_rec.from_str(mods_str)
62
- expect(smods_rec.send(method_sym)).to eq method_sym.to_s =~ /int/ ? 2015 : '2015'
63
- end
64
- context 'spotlight actual data' do
65
- require 'fixtures/spotlight_pub_date_data'
66
- SPOTLIGHT_PUB_DATE_DATA.each_pair.each do |coll_name, coll_data|
67
- # papyri - the only Spotlight data with BC dates
68
- next if coll_name == 'papyri' && method_sym == :pub_year_int
69
-
70
- coll_data.each_pair do |mods_str, exp_vals|
71
- expected = exp_vals[exp_val_position]
72
- it "#{expected} for rec in #{coll_name}" do
73
- smods_rec.from_str(mods_str)
74
- expect(smods_rec.send(method_sym)).to eq((method_sym.to_s =~ /int/ ? expected.to_i : expected)) if expected
75
- end
141
+ context 'when it has a date range' do
142
+ let(:modsxml) do
143
+ <<-EOF
144
+ <mods xmlns="http://www.loc.gov/mods/v3">
145
+ <originInfo>
146
+ <dateIssued point="start">1800</dateIssued>
147
+ <dateIssued point="end">1900</dateIssued>
148
+ </originInfo>
149
+ </mods>
150
+ EOF
151
+ end
152
+
153
+ it 'returns the date range' do
154
+ expect(record.pub_year_display_str).to eq '1800 - 1900'
155
+ end
156
+ end
157
+
158
+ context 'when it has an open-ended date range' do
159
+ let(:modsxml) do
160
+ <<-EOF
161
+ <mods xmlns="http://www.loc.gov/mods/v3">
162
+ <originInfo>
163
+ <dateIssued point="start">uuuu</dateIssued>
164
+ <dateIssued point="end">1900</dateIssued>
165
+ </originInfo>
166
+ </mods>
167
+ EOF
168
+ end
169
+
170
+ it 'returns the date range' do
171
+ expect(record.pub_year_display_str).to eq ' - 1900'
172
+ end
173
+ end
174
+
175
+ context 'when it has an encoded date' do
176
+ let(:modsxml) do
177
+ <<-EOF
178
+ <mods xmlns="http://www.loc.gov/mods/v3">
179
+ <originInfo>
180
+ <dateIssued>1800</dateIssued>
181
+ <dateIssued encoding="marc">1900</dateIssued>
182
+ </originInfo>
183
+ </mods>
184
+ EOF
185
+ end
186
+
187
+ it 'returns the encoded date' do
188
+ expect(record.pub_year_display_str).to eq '1900'
189
+ end
190
+ end
191
+
192
+ context 'when it has a date range and an earlier single date' do
193
+ let(:modsxml) do
194
+ <<-EOF
195
+ <mods xmlns="http://www.loc.gov/mods/v3">
196
+ <originInfo>
197
+ <dateIssued>1799</dateIssued>
198
+ <dateIssued point="start">1800</dateIssued>
199
+ <dateIssued point="end">1900</dateIssued>
200
+ </originInfo>
201
+ </mods>
202
+ EOF
203
+ end
204
+
205
+ it 'returns the earliest date' do
206
+ expect(record.pub_year_display_str).to eq '1799'
207
+ end
208
+ end
209
+
210
+ context 'when it has a date range and a later single date' do
211
+ let(:modsxml) do
212
+ <<-EOF
213
+ <mods xmlns="http://www.loc.gov/mods/v3">
214
+ <originInfo>
215
+ <dateIssued>1850</dateIssued>
216
+ <dateIssued point="start">1800</dateIssued>
217
+ <dateIssued point="end">1900</dateIssued>
218
+ </originInfo>
219
+ </mods>
220
+ EOF
221
+ end
222
+
223
+ it 'returns the date range' do
224
+ expect(record.pub_year_display_str).to eq '1800 - 1900'
225
+ end
226
+ end
227
+
228
+ context 'with BCE dates' do
229
+ let(:modsxml) do
230
+ <<-EOF
231
+ <mods xmlns="http://www.loc.gov/mods/v3">
232
+ <originInfo>
233
+ <dateIssued encoding="edtf">-0249</dateIssued>
234
+ <dateIssued encoding="edtf">-0149</dateIssued>
235
+ </originInfo>
236
+ </mods>
237
+ EOF
238
+ end
239
+
240
+ it 'returns the earliest date' do
241
+ expect(record.pub_year_display_str).to eq '250 BCE'
242
+ end
243
+ end
244
+
245
+ context 'with a BCE date range' do
246
+ let(:modsxml) do
247
+ <<-EOF
248
+ <mods xmlns="http://www.loc.gov/mods/v3">
249
+ <originInfo>
250
+ <dateIssued encoding="edtf" point="start">-0249</dateIssued>
251
+ <dateIssued encoding="edtf" point="end">-0149</dateIssued>
252
+ </originInfo>
253
+ </mods>
254
+ EOF
255
+ end
256
+
257
+ it 'returns the date range' do
258
+ expect(record.pub_year_display_str).to eq '250 BCE - 150 BCE'
259
+ end
260
+ end
261
+
262
+ context 'with a qualified date' do
263
+ let(:modsxml) do
264
+ <<-EOF
265
+ <mods xmlns="http://www.loc.gov/mods/v3">
266
+ <originInfo>
267
+ <dateIssued qualifier="approximate">249</dateIssued>
268
+ </originInfo>
269
+ </mods>
270
+ EOF
271
+ end
272
+
273
+ it 'returns the date without any qualifiers' do
274
+ expect(record.pub_year_display_str).to eq '249 CE'
275
+ end
276
+
277
+ context 'with ignore_approximate: true' do
278
+ it 'returns nothing' do
279
+ expect(record.pub_year_display_str(ignore_approximate: true)).to eq nil
76
280
  end
77
281
  end
78
282
  end
79
- end
80
283
 
81
- context '#pub_year_display_str' do
82
- it_behaves_like "single pub date value", :pub_year_display_str, 1
284
+ context 'with non-year data in the field' do
285
+ let(:modsxml) do
286
+ <<-EOF
287
+ <mods xmlns="http://www.loc.gov/mods/v3">
288
+ <originInfo>
289
+ <dateIssued>12th May 1800</dateIssued>
290
+ </originInfo>
291
+ </mods>
292
+ EOF
293
+ end
294
+
295
+ it 'returns only the year part of the date' do
296
+ expect(record.pub_year_display_str).to eq '1800'
297
+ end
298
+ end
299
+
300
+ context 'with a placeholder dates' do
301
+ let(:modsxml) do
302
+ <<-EOF
303
+ <mods xmlns="http://www.loc.gov/mods/v3">
304
+ <originInfo>
305
+ <dateIssued qualifier="approximate">9999</dateIssued>
306
+ </originInfo>
307
+ </mods>
308
+ EOF
309
+ end
310
+
311
+ it 'ignores the date' do
312
+ expect(record.pub_year_display_str).to eq nil
313
+ end
314
+ end
83
315
  end
84
316
 
85
317
  context '#pub_year_sort_str' do
86
- it_behaves_like "single pub date value", :pub_year_sort_str, 0
318
+ context 'when it has a dateIssued date' do
319
+ let(:modsxml) do
320
+ <<-EOF
321
+ <mods xmlns="http://www.loc.gov/mods/v3">
322
+ <originInfo>
323
+ <dateIssued>1900</dateIssued>
324
+ </originInfo>
325
+ </mods>
326
+ EOF
327
+ end
328
+
329
+ it 'returns the year from the field' do
330
+ expect(record.pub_year_sort_str).to eq '1900'
331
+ end
332
+ end
333
+
334
+ context 'when it has a date range' do
335
+ let(:modsxml) do
336
+ <<-EOF
337
+ <mods xmlns="http://www.loc.gov/mods/v3">
338
+ <originInfo>
339
+ <dateIssued point="start">1800</dateIssued>
340
+ <dateIssued point="end">1900</dateIssued>
341
+ </originInfo>
342
+ </mods>
343
+ EOF
344
+ end
345
+
346
+ it 'returns just the earliest date in the range' do
347
+ expect(record.pub_year_sort_str).to eq '1800'
348
+ end
349
+ end
350
+
351
+ context 'with BCE dates' do
352
+ let(:modsxml) do
353
+ <<-EOF
354
+ <mods xmlns="http://www.loc.gov/mods/v3">
355
+ <originInfo>
356
+ <dateIssued encoding="edtf">-0249</dateIssued>
357
+ <dateIssued encoding="edtf">-0149</dateIssued>
358
+ </originInfo>
359
+ </mods>
360
+ EOF
361
+ end
362
+
363
+ it 'returns the earliest date with the funky lexical sort encoding' do
364
+ expect(record.pub_year_sort_str).to eq '-751'
365
+ end
366
+ end
367
+
368
+ context 'with a BCE date range' do
369
+ let(:modsxml) do
370
+ <<-EOF
371
+ <mods xmlns="http://www.loc.gov/mods/v3">
372
+ <originInfo>
373
+ <dateIssued encoding="edtf" point="start">-0249</dateIssued>
374
+ <dateIssued encoding="edtf" point="end">-0149</dateIssued>
375
+ </originInfo>
376
+ </mods>
377
+ EOF
378
+ end
379
+
380
+ it 'returns the earliest date of the range with the funky lexical sort encoding' do
381
+ expect(record.pub_year_sort_str).to eq '-751'
382
+ end
383
+ end
384
+
385
+ context 'with a qualified date' do
386
+ let(:modsxml) do
387
+ <<-EOF
388
+ <mods xmlns="http://www.loc.gov/mods/v3">
389
+ <originInfo>
390
+ <dateIssued qualifier="approximate">249</dateIssued>
391
+ </originInfo>
392
+ </mods>
393
+ EOF
394
+ end
395
+
396
+ it 'returns the date without any qualifiers' do
397
+ expect(record.pub_year_sort_str).to eq '0249'
398
+ end
399
+
400
+ context 'with ignore_approximate: true' do
401
+ it 'returns nothing' do
402
+ expect(record.pub_year_sort_str(ignore_approximate: true)).to eq nil
403
+ end
404
+ end
405
+ end
406
+
407
+ context 'with a placeholder dates' do
408
+ let(:modsxml) do
409
+ <<-EOF
410
+ <mods xmlns="http://www.loc.gov/mods/v3">
411
+ <originInfo>
412
+ <dateIssued qualifier="approximate">9999</dateIssued>
413
+ </originInfo>
414
+ </mods>
415
+ EOF
416
+ end
417
+
418
+ it 'ignores the date' do
419
+ expect(record.pub_year_sort_str).to eq nil
420
+ end
421
+ end
422
+
423
+ context 'when it has an open-ended date range' do
424
+ let(:modsxml) do
425
+ <<-EOF
426
+ <mods xmlns="http://www.loc.gov/mods/v3">
427
+ <originInfo>
428
+ <dateIssued point="start">uuuu</dateIssued>
429
+ <dateIssued point="end">1900</dateIssued>
430
+ </originInfo>
431
+ </mods>
432
+ EOF
433
+ end
434
+
435
+ it 'returns the known part of the date range' do
436
+ expect(record.pub_year_sort_str).to eq '1900'
437
+ end
438
+ end
87
439
  end
88
440
 
89
441
  context '#pub_year_int' do
90
- it_behaves_like "single pub date value", :pub_year_int, 0
91
- # papyri - the only Spotlight data with BC dates
92
- it '-200 for 200 B.C.' do
93
- # hd778hw9236
94
- mods_str = mods_origin_info_start_str +
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
- mods_origin_info_end_str
98
- smods_rec.from_str(mods_str)
99
- expect(smods_rec.pub_year_int).to eq(-199)
100
- end
101
- it '-211 for 211 B.C.' do
102
- # ww728rz0477
103
- mods_str = mods_origin_info_start_str +
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
- mods_origin_info_end_str
107
- smods_rec.from_str(mods_str)
108
- expect(smods_rec.pub_year_int).to eq(-210)
442
+ context 'when it has a dateIssued date' do
443
+ let(:modsxml) do
444
+ <<-EOF
445
+ <mods xmlns="http://www.loc.gov/mods/v3">
446
+ <originInfo>
447
+ <dateIssued>1900</dateIssued>
448
+ </originInfo>
449
+ </mods>
450
+ EOF
451
+ end
452
+
453
+ it 'returns the year from the dateIssued field' do
454
+ expect(record.pub_year_int).to eq 1900
455
+ end
109
456
  end
110
- end
111
457
 
112
- context '*best_or_earliest_year' do
113
- it 'selects earliest (valid) parseable date from multiple options' do
114
- mods_str = mods_origin_info_start_str +
115
- '<dateIssued point="start" qualifier="questionable">1758</dateIssued>' +
116
- '<dateIssued point="end" qualifier="questionable">uuuu</dateIssued>' +
117
- '<dateIssued>1753]</dateIssued>' +
118
- mods_origin_info_end_str
119
- smods_rec.from_str(mods_str)
120
- expect(Stanford::Mods::OriginInfo.best_or_earliest_year(smods_rec.origin_info.dateIssued).xml.text).to eq '1753]'
121
- end
122
- it 'ignores encoding' do
123
- # encoding matters for choosing display, not for parsing year
124
- mods_str = mods_origin_info_start_str +
125
- '<dateIssued>1100</dateIssued>' +
126
- '<dateIssued encoding="marc">1200</dateIssued>' +
127
- '<dateIssued encoding="w3cdtf">1300</dateIssued>' +
128
- mods_origin_info_end_str
129
- smods_rec.from_str(mods_str)
130
- expect(Stanford::Mods::OriginInfo.best_or_earliest_year(smods_rec.origin_info.dateIssued).xml.text).to eq '1100'
131
- mods_str = mods_origin_info_start_str +
132
- '<dateIssued>1200</dateIssued>' +
133
- '<dateIssued encoding="marc">1300</dateIssued>' +
134
- '<dateIssued encoding="w3cdtf">1100</dateIssued>' +
135
- mods_origin_info_end_str
136
- smods_rec.from_str(mods_str)
137
- expect(Stanford::Mods::OriginInfo.best_or_earliest_year(smods_rec.origin_info.dateIssued).xml.text).to eq '1100'
138
- mods_str = mods_origin_info_start_str +
139
- '<dateIssued>1300</dateIssued>' +
140
- '<dateIssued encoding="marc">1100</dateIssued>' +
141
- '<dateIssued encoding="w3cdtf">1200</dateIssued>' +
142
- mods_origin_info_end_str
143
- smods_rec.from_str(mods_str)
144
- expect(Stanford::Mods::OriginInfo.best_or_earliest_year(smods_rec.origin_info.dateIssued).xml.text).to eq '1100'
458
+ context 'when it has multiple dates' do
459
+ let(:modsxml) do
460
+ <<-EOF
461
+ <mods xmlns="http://www.loc.gov/mods/v3">
462
+ <originInfo>
463
+ <dateIssued>1900</dateIssued>
464
+ <dateIssued>1800</dateIssued>
465
+ </originInfo>
466
+ </mods>
467
+ EOF
468
+ end
469
+
470
+ it 'returns the earliest year' do
471
+ expect(record.pub_year_int).to eq 1800
472
+ end
145
473
  end
146
- end
147
474
 
148
- RSpec.shared_examples "pub date best single value" do |method_sym|
149
- it 'uses keyDate value if specified' do
150
- mods_str = mods_origin_info_start_str +
151
- '<dateIssued>1666</dateIssued>' +
152
- '<dateIssued keyDate="yes">2014</dateIssued>' +
153
- mods_origin_info_end_str
154
- smods_rec.from_str(mods_str)
155
- expect(smods_rec.send(method_sym, smods_rec.origin_info.dateIssued)).to eq method_sym.to_s =~ /int/ ? 2014 : '2014'
156
- end
157
- it 'ignores invalid keyDate value' do
158
- mods_str = mods_origin_info_start_str +
159
- '<dateIssued keyDate="6th">1500</dateIssued>' +
160
- '<dateIssued>1499</dateIssued>' +
161
- mods_origin_info_end_str
162
- smods_rec.from_str(mods_str)
163
- expect(smods_rec.send(method_sym, smods_rec.origin_info.dateIssued)).to eq method_sym.to_s =~ /int/ ? 1499 : '1499'
164
- end
165
- it 'calls earliest_year if multiple keyDates present' do
166
- mods_str = mods_origin_info_start_str +
167
- '<dateCreated keyDate="yes">2003</dateCreated>' +
168
- '<dateCreated keyDate="yes">2001</dateCreated>' +
169
- mods_origin_info_end_str
170
- smods_rec.from_str(mods_str)
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))
173
- end
174
- it 'calls earliest_year if no keyDate' do
175
- mods_str = mods_origin_info_start_str +
176
- '<dateIssued>1753]</dateIssued>' +
177
- '<dateIssued point="start" qualifier="questionable">1758</dateIssued>' +
178
- '<dateIssued point="end" qualifier="questionable">uuuu</dateIssued>' +
179
- mods_origin_info_end_str
180
- smods_rec.from_str(mods_str)
181
- if method_sym.to_s =~ /int/
182
- expect(Stanford::Mods::OriginInfo).to receive(:best_or_earliest_year).with(smods_rec.origin_info.dateIssued)
183
- else
184
- expect(Stanford::Mods::OriginInfo).to receive(:best_or_earliest_year).with(smods_rec.origin_info.dateIssued)
185
- end
186
- smods_rec.send(method_sym, smods_rec.origin_info.dateIssued)
187
- end
188
- it 'ignores encoding' do
189
- # encoding matters for choosing display, not for parsing year
190
- mods_str = mods_origin_info_start_str +
191
- '<dateIssued keyDate="yes">1100</dateIssued>' +
192
- '<dateIssued encoding="marc">1200</dateIssued>' +
193
- '<dateIssued encoding="w3cdtf">1300</dateIssued>' +
194
- mods_origin_info_end_str
195
- smods_rec.from_str(mods_str)
196
- expect(smods_rec.send(method_sym, smods_rec.origin_info.dateIssued)).to eq method_sym.to_s =~ /int/ ? 1100 : '1100'
197
- mods_str = mods_origin_info_start_str +
198
- '<dateIssued>1200</dateIssued>' +
199
- '<dateIssued encoding="marc">1300</dateIssued>' +
200
- '<dateIssued encoding="w3cdtf" keyDate="yes">1100</dateIssued>' +
201
- mods_origin_info_end_str
202
- smods_rec.from_str(mods_str)
203
- expect(smods_rec.send(method_sym, smods_rec.origin_info.dateIssued)).to eq method_sym.to_s =~ /int/ ? 1100 : '1100'
204
- mods_str = mods_origin_info_start_str +
205
- '<dateIssued>1300</dateIssued>' +
206
- '<dateIssued encoding="marc" keyDate="yes">1100</dateIssued>' +
207
- '<dateIssued encoding="w3cdtf">1200</dateIssued>' +
208
- mods_origin_info_end_str
209
- smods_rec.from_str(mods_str)
210
- expect(smods_rec.send(method_sym, smods_rec.origin_info.dateIssued)).to eq method_sym.to_s =~ /int/ ? 1100 : '1100'
475
+ context 'when it has a date range' do
476
+ let(:modsxml) do
477
+ <<-EOF
478
+ <mods xmlns="http://www.loc.gov/mods/v3">
479
+ <originInfo>
480
+ <dateIssued point="start">1800</dateIssued>
481
+ <dateIssued point="end">1900</dateIssued>
482
+ </originInfo>
483
+ </mods>
484
+ EOF
485
+ end
486
+
487
+ it 'returns the earliest year from the date range' do
488
+ expect(record.pub_year_int).to eq 1800
489
+ end
211
490
  end
212
- end
213
491
 
214
- context '*is_approximate' do
215
- it 'removes elements when date_is_approximate? returns true' do
216
- mods_str = "#{mods_origin_info_start_str}
217
- <dateIssued>1900</dateIssued>
218
- <dateIssued qualifier='inferred'>1910</dateIssued>
219
- <dateIssued qualifier='questionable'>1930</dateIssued>
220
- #{mods_origin_info_end_str}"
221
- smods_rec.from_str(mods_str)
222
- elements = smods_rec.origin_info.dateIssued
223
- expect(elements.size).to eq 3
224
- result = elements.reject { |n| smods_rec.is_approximate(n) }
225
- expect(result).to be_instance_of(Array)
226
- expect(result.size).to eq 2
492
+ context 'when it has an open-ended date range' do
493
+ let(:modsxml) do
494
+ <<-EOF
495
+ <mods xmlns="http://www.loc.gov/mods/v3">
496
+ <originInfo>
497
+ <dateIssued point="start">uuuu</dateIssued>
498
+ <dateIssued point="end">1900</dateIssued>
499
+ </originInfo>
500
+ </mods>
501
+ EOF
502
+ end
503
+
504
+ it 'returns the known part of the date range' do
505
+ expect(record.pub_year_int).to eq 1900
506
+ end
507
+ end
508
+
509
+ context 'with BCE dates' do
510
+ let(:modsxml) do
511
+ <<-EOF
512
+ <mods xmlns="http://www.loc.gov/mods/v3">
513
+ <originInfo>
514
+ <dateIssued encoding="edtf">-0249</dateIssued>
515
+ <dateIssued encoding="edtf">-0149</dateIssued>
516
+ </originInfo>
517
+ </mods>
518
+ EOF
519
+ end
520
+
521
+ it 'returns the earliest date' do
522
+ expect(record.pub_year_int).to eq(-249)
523
+ end
524
+ end
525
+
526
+ context 'with a BCE date range' do
527
+ let(:modsxml) do
528
+ <<-EOF
529
+ <mods xmlns="http://www.loc.gov/mods/v3">
530
+ <originInfo>
531
+ <dateIssued encoding="edtf" point="start">-0249</dateIssued>
532
+ <dateIssued encoding="edtf" point="end">-0149</dateIssued>
533
+ </originInfo>
534
+ </mods>
535
+ EOF
536
+ end
537
+
538
+ it 'returns the year of the earliest date in the range' do
539
+ expect(record.pub_year_int).to eq(-249)
540
+ end
541
+ end
542
+
543
+ context 'with a qualified date' do
544
+ let(:modsxml) do
545
+ <<-EOF
546
+ <mods xmlns="http://www.loc.gov/mods/v3">
547
+ <originInfo>
548
+ <dateIssued qualifier="approximate">249</dateIssued>
549
+ </originInfo>
550
+ </mods>
551
+ EOF
552
+ end
553
+
554
+ it 'returns the date without any qualifiers' do
555
+ expect(record.pub_year_int).to eq 249
556
+ end
557
+
558
+ context 'with ignore_approximate: true' do
559
+ it 'returns nothing' do
560
+ expect(record.pub_year_int(ignore_approximate: true)).to eq nil
561
+ end
562
+ end
563
+ end
564
+
565
+ context 'with a placeholder dates' do
566
+ let(:modsxml) do
567
+ <<-EOF
568
+ <mods xmlns="http://www.loc.gov/mods/v3">
569
+ <originInfo>
570
+ <dateIssued qualifier="approximate">9999</dateIssued>
571
+ </originInfo>
572
+ </mods>
573
+ EOF
574
+ end
575
+
576
+ it 'ignores the date' do
577
+ expect(record.pub_year_int).to eq nil
578
+ end
227
579
  end
228
580
  end
229
581
  end