stanford-mods 3.1.0 → 3.3.1
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.
- checksums.yaml +4 -4
- data/lib/stanford-mods/concerns/origin_info.rb +49 -54
- data/lib/stanford-mods/imprint.rb +123 -52
- data/lib/stanford-mods/version.rb +1 -1
- data/lib/stanford-mods.rb +1 -2
- data/spec/fixtures/searchworks_imprint_data.rb +11 -11
- data/spec/imprint_spec.rb +11 -11
- data/spec/origin_info_spec.rb +566 -208
- data/spec/sw_publication_spec.rb +0 -24
- data/stanford-mods.gemspec +1 -1
- metadata +5 -10
- data/lib/stanford-mods/date_parsing.rb +0 -70
- data/spec/fixtures/searchworks_pub_date_data.rb +0 -979
- data/spec/fixtures/spotlight_pub_date_data.rb +0 -316
data/spec/origin_info_spec.rb
CHANGED
@@ -1,229 +1,587 @@
|
|
1
1
|
describe "computations from /originInfo field" do
|
2
|
-
let(:
|
3
|
-
|
4
|
-
#
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
16
70
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
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
|
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
|
+
|
104
|
+
context 'with field filters' do
|
105
|
+
it 'returns the year from the requested field' do
|
106
|
+
expect(record.pub_year_display_str([:dateCreated])).to eq '1900'
|
76
107
|
end
|
77
108
|
end
|
78
109
|
end
|
79
|
-
end
|
80
110
|
|
81
|
-
|
82
|
-
|
111
|
+
context 'when it has multiple dates' do
|
112
|
+
let(:modsxml) do
|
113
|
+
<<-EOF
|
114
|
+
<mods xmlns="http://www.loc.gov/mods/v3">
|
115
|
+
<originInfo>
|
116
|
+
<dateIssued>1900</dateIssued>
|
117
|
+
<dateIssued>1800</dateIssued>
|
118
|
+
</originInfo>
|
119
|
+
</mods>
|
120
|
+
EOF
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'returns the earliest year' do
|
124
|
+
expect(record.pub_year_display_str).to eq '1800'
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
context 'when it has multiple originInfo elements' do
|
129
|
+
let(:modsxml) do
|
130
|
+
<<-EOF
|
131
|
+
<mods xmlns="http://www.loc.gov/mods/v3">
|
132
|
+
<originInfo>
|
133
|
+
<dateIssued>1900</dateIssued>
|
134
|
+
</originInfo>
|
135
|
+
<originInfo>
|
136
|
+
<dateIssued>1800</dateIssued>
|
137
|
+
</originInfo>
|
138
|
+
</mods>
|
139
|
+
EOF
|
140
|
+
end
|
141
|
+
|
142
|
+
it 'returns the earliest year across all the dates' do
|
143
|
+
expect(record.pub_year_display_str).to eq '1800'
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
context 'when it has a date range' do
|
148
|
+
let(:modsxml) do
|
149
|
+
<<-EOF
|
150
|
+
<mods xmlns="http://www.loc.gov/mods/v3">
|
151
|
+
<originInfo>
|
152
|
+
<dateIssued point="start">1800</dateIssued>
|
153
|
+
<dateIssued point="end">1900</dateIssued>
|
154
|
+
</originInfo>
|
155
|
+
</mods>
|
156
|
+
EOF
|
157
|
+
end
|
158
|
+
|
159
|
+
it 'returns the date range' do
|
160
|
+
expect(record.pub_year_display_str).to eq '1800 - 1900'
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
context 'when it has an open-ended date range' do
|
165
|
+
let(:modsxml) do
|
166
|
+
<<-EOF
|
167
|
+
<mods xmlns="http://www.loc.gov/mods/v3">
|
168
|
+
<originInfo>
|
169
|
+
<dateIssued point="start">uuuu</dateIssued>
|
170
|
+
<dateIssued point="end">1900</dateIssued>
|
171
|
+
</originInfo>
|
172
|
+
</mods>
|
173
|
+
EOF
|
174
|
+
end
|
175
|
+
|
176
|
+
it 'returns the date range' do
|
177
|
+
expect(record.pub_year_display_str).to eq ' - 1900'
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
context 'when it has an encoded date' do
|
182
|
+
let(:modsxml) do
|
183
|
+
<<-EOF
|
184
|
+
<mods xmlns="http://www.loc.gov/mods/v3">
|
185
|
+
<originInfo>
|
186
|
+
<dateIssued>1800</dateIssued>
|
187
|
+
<dateIssued encoding="marc">1900</dateIssued>
|
188
|
+
</originInfo>
|
189
|
+
</mods>
|
190
|
+
EOF
|
191
|
+
end
|
192
|
+
|
193
|
+
it 'returns the encoded date' do
|
194
|
+
expect(record.pub_year_display_str).to eq '1900'
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
context 'when it has a date range and an earlier single date' do
|
199
|
+
let(:modsxml) do
|
200
|
+
<<-EOF
|
201
|
+
<mods xmlns="http://www.loc.gov/mods/v3">
|
202
|
+
<originInfo>
|
203
|
+
<dateIssued>1799</dateIssued>
|
204
|
+
<dateIssued point="start">1800</dateIssued>
|
205
|
+
<dateIssued point="end">1900</dateIssued>
|
206
|
+
</originInfo>
|
207
|
+
</mods>
|
208
|
+
EOF
|
209
|
+
end
|
210
|
+
|
211
|
+
it 'returns the earliest date' do
|
212
|
+
expect(record.pub_year_display_str).to eq '1799'
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
context 'when it has a date range and a later single date' do
|
217
|
+
let(:modsxml) do
|
218
|
+
<<-EOF
|
219
|
+
<mods xmlns="http://www.loc.gov/mods/v3">
|
220
|
+
<originInfo>
|
221
|
+
<dateIssued>1850</dateIssued>
|
222
|
+
<dateIssued point="start">1800</dateIssued>
|
223
|
+
<dateIssued point="end">1900</dateIssued>
|
224
|
+
</originInfo>
|
225
|
+
</mods>
|
226
|
+
EOF
|
227
|
+
end
|
228
|
+
|
229
|
+
it 'returns the date range' do
|
230
|
+
expect(record.pub_year_display_str).to eq '1800 - 1900'
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
context 'with BCE dates' do
|
235
|
+
let(:modsxml) do
|
236
|
+
<<-EOF
|
237
|
+
<mods xmlns="http://www.loc.gov/mods/v3">
|
238
|
+
<originInfo>
|
239
|
+
<dateIssued encoding="edtf">-0249</dateIssued>
|
240
|
+
<dateIssued encoding="edtf">-0149</dateIssued>
|
241
|
+
</originInfo>
|
242
|
+
</mods>
|
243
|
+
EOF
|
244
|
+
end
|
245
|
+
|
246
|
+
it 'returns the earliest date' do
|
247
|
+
expect(record.pub_year_display_str).to eq '250 BCE'
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
context 'with a BCE date range' do
|
252
|
+
let(:modsxml) do
|
253
|
+
<<-EOF
|
254
|
+
<mods xmlns="http://www.loc.gov/mods/v3">
|
255
|
+
<originInfo>
|
256
|
+
<dateIssued encoding="edtf" point="start">-0249</dateIssued>
|
257
|
+
<dateIssued encoding="edtf" point="end">-0149</dateIssued>
|
258
|
+
</originInfo>
|
259
|
+
</mods>
|
260
|
+
EOF
|
261
|
+
end
|
262
|
+
|
263
|
+
it 'returns the date range' do
|
264
|
+
expect(record.pub_year_display_str).to eq '250 BCE - 150 BCE'
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
context 'with a qualified date' do
|
269
|
+
let(:modsxml) do
|
270
|
+
<<-EOF
|
271
|
+
<mods xmlns="http://www.loc.gov/mods/v3">
|
272
|
+
<originInfo>
|
273
|
+
<dateIssued qualifier="approximate">249</dateIssued>
|
274
|
+
</originInfo>
|
275
|
+
</mods>
|
276
|
+
EOF
|
277
|
+
end
|
278
|
+
|
279
|
+
it 'returns the date without any qualifiers' do
|
280
|
+
expect(record.pub_year_display_str).to eq '249 CE'
|
281
|
+
end
|
282
|
+
|
283
|
+
context 'with ignore_approximate: true' do
|
284
|
+
it 'returns nothing' do
|
285
|
+
expect(record.pub_year_display_str(ignore_approximate: true)).to eq nil
|
286
|
+
end
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
290
|
+
context 'with non-year data in the field' do
|
291
|
+
let(:modsxml) do
|
292
|
+
<<-EOF
|
293
|
+
<mods xmlns="http://www.loc.gov/mods/v3">
|
294
|
+
<originInfo>
|
295
|
+
<dateIssued>12th May 1800</dateIssued>
|
296
|
+
</originInfo>
|
297
|
+
</mods>
|
298
|
+
EOF
|
299
|
+
end
|
300
|
+
|
301
|
+
it 'returns only the year part of the date' do
|
302
|
+
expect(record.pub_year_display_str).to eq '1800'
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
306
|
+
context 'with a placeholder dates' do
|
307
|
+
let(:modsxml) do
|
308
|
+
<<-EOF
|
309
|
+
<mods xmlns="http://www.loc.gov/mods/v3">
|
310
|
+
<originInfo>
|
311
|
+
<dateIssued qualifier="approximate">9999</dateIssued>
|
312
|
+
</originInfo>
|
313
|
+
</mods>
|
314
|
+
EOF
|
315
|
+
end
|
316
|
+
|
317
|
+
it 'ignores the date' do
|
318
|
+
expect(record.pub_year_display_str).to eq nil
|
319
|
+
end
|
320
|
+
end
|
83
321
|
end
|
84
322
|
|
85
323
|
context '#pub_year_sort_str' do
|
86
|
-
|
324
|
+
context 'when it has a dateIssued date' do
|
325
|
+
let(:modsxml) do
|
326
|
+
<<-EOF
|
327
|
+
<mods xmlns="http://www.loc.gov/mods/v3">
|
328
|
+
<originInfo>
|
329
|
+
<dateIssued>1900</dateIssued>
|
330
|
+
</originInfo>
|
331
|
+
</mods>
|
332
|
+
EOF
|
333
|
+
end
|
334
|
+
|
335
|
+
it 'returns the year from the field' do
|
336
|
+
expect(record.pub_year_sort_str).to eq '1900'
|
337
|
+
end
|
338
|
+
end
|
339
|
+
|
340
|
+
context 'when it has a date range' do
|
341
|
+
let(:modsxml) do
|
342
|
+
<<-EOF
|
343
|
+
<mods xmlns="http://www.loc.gov/mods/v3">
|
344
|
+
<originInfo>
|
345
|
+
<dateIssued point="start">1800</dateIssued>
|
346
|
+
<dateIssued point="end">1900</dateIssued>
|
347
|
+
</originInfo>
|
348
|
+
</mods>
|
349
|
+
EOF
|
350
|
+
end
|
351
|
+
|
352
|
+
it 'returns just the earliest date in the range' do
|
353
|
+
expect(record.pub_year_sort_str).to eq '1800'
|
354
|
+
end
|
355
|
+
end
|
356
|
+
|
357
|
+
context 'with BCE dates' do
|
358
|
+
let(:modsxml) do
|
359
|
+
<<-EOF
|
360
|
+
<mods xmlns="http://www.loc.gov/mods/v3">
|
361
|
+
<originInfo>
|
362
|
+
<dateIssued encoding="edtf">-0249</dateIssued>
|
363
|
+
<dateIssued encoding="edtf">-0149</dateIssued>
|
364
|
+
</originInfo>
|
365
|
+
</mods>
|
366
|
+
EOF
|
367
|
+
end
|
368
|
+
|
369
|
+
it 'returns the earliest date with the funky lexical sort encoding' do
|
370
|
+
expect(record.pub_year_sort_str).to eq '-751'
|
371
|
+
end
|
372
|
+
end
|
373
|
+
|
374
|
+
context 'with a BCE date range' do
|
375
|
+
let(:modsxml) do
|
376
|
+
<<-EOF
|
377
|
+
<mods xmlns="http://www.loc.gov/mods/v3">
|
378
|
+
<originInfo>
|
379
|
+
<dateIssued encoding="edtf" point="start">-0249</dateIssued>
|
380
|
+
<dateIssued encoding="edtf" point="end">-0149</dateIssued>
|
381
|
+
</originInfo>
|
382
|
+
</mods>
|
383
|
+
EOF
|
384
|
+
end
|
385
|
+
|
386
|
+
it 'returns the earliest date of the range with the funky lexical sort encoding' do
|
387
|
+
expect(record.pub_year_sort_str).to eq '-751'
|
388
|
+
end
|
389
|
+
end
|
390
|
+
|
391
|
+
context 'with a qualified date' do
|
392
|
+
let(:modsxml) do
|
393
|
+
<<-EOF
|
394
|
+
<mods xmlns="http://www.loc.gov/mods/v3">
|
395
|
+
<originInfo>
|
396
|
+
<dateIssued qualifier="approximate">249</dateIssued>
|
397
|
+
</originInfo>
|
398
|
+
</mods>
|
399
|
+
EOF
|
400
|
+
end
|
401
|
+
|
402
|
+
it 'returns the date without any qualifiers' do
|
403
|
+
expect(record.pub_year_sort_str).to eq '0249'
|
404
|
+
end
|
405
|
+
|
406
|
+
context 'with ignore_approximate: true' do
|
407
|
+
it 'returns nothing' do
|
408
|
+
expect(record.pub_year_sort_str(ignore_approximate: true)).to eq nil
|
409
|
+
end
|
410
|
+
end
|
411
|
+
end
|
412
|
+
|
413
|
+
context 'with a placeholder dates' do
|
414
|
+
let(:modsxml) do
|
415
|
+
<<-EOF
|
416
|
+
<mods xmlns="http://www.loc.gov/mods/v3">
|
417
|
+
<originInfo>
|
418
|
+
<dateIssued qualifier="approximate">9999</dateIssued>
|
419
|
+
</originInfo>
|
420
|
+
</mods>
|
421
|
+
EOF
|
422
|
+
end
|
423
|
+
|
424
|
+
it 'ignores the date' do
|
425
|
+
expect(record.pub_year_sort_str).to eq nil
|
426
|
+
end
|
427
|
+
end
|
428
|
+
|
429
|
+
context 'when it has an open-ended date range' do
|
430
|
+
let(:modsxml) do
|
431
|
+
<<-EOF
|
432
|
+
<mods xmlns="http://www.loc.gov/mods/v3">
|
433
|
+
<originInfo>
|
434
|
+
<dateIssued point="start">uuuu</dateIssued>
|
435
|
+
<dateIssued point="end">1900</dateIssued>
|
436
|
+
</originInfo>
|
437
|
+
</mods>
|
438
|
+
EOF
|
439
|
+
end
|
440
|
+
|
441
|
+
it 'returns the known part of the date range' do
|
442
|
+
expect(record.pub_year_sort_str).to eq '1900'
|
443
|
+
end
|
444
|
+
end
|
87
445
|
end
|
88
446
|
|
89
447
|
context '#pub_year_int' do
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
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)
|
448
|
+
context 'when it has a dateIssued date' do
|
449
|
+
let(:modsxml) do
|
450
|
+
<<-EOF
|
451
|
+
<mods xmlns="http://www.loc.gov/mods/v3">
|
452
|
+
<originInfo>
|
453
|
+
<dateIssued>1900</dateIssued>
|
454
|
+
</originInfo>
|
455
|
+
</mods>
|
456
|
+
EOF
|
457
|
+
end
|
458
|
+
|
459
|
+
it 'returns the year from the dateIssued field' do
|
460
|
+
expect(record.pub_year_int).to eq 1900
|
461
|
+
end
|
109
462
|
end
|
110
|
-
end
|
111
463
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
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'
|
464
|
+
context 'when it has multiple dates' do
|
465
|
+
let(:modsxml) do
|
466
|
+
<<-EOF
|
467
|
+
<mods xmlns="http://www.loc.gov/mods/v3">
|
468
|
+
<originInfo>
|
469
|
+
<dateIssued>1900</dateIssued>
|
470
|
+
<dateIssued>1800</dateIssued>
|
471
|
+
</originInfo>
|
472
|
+
</mods>
|
473
|
+
EOF
|
474
|
+
end
|
475
|
+
|
476
|
+
it 'returns the earliest year' do
|
477
|
+
expect(record.pub_year_int).to eq 1800
|
478
|
+
end
|
145
479
|
end
|
146
|
-
end
|
147
480
|
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
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'
|
481
|
+
context 'when it has a date range' do
|
482
|
+
let(:modsxml) do
|
483
|
+
<<-EOF
|
484
|
+
<mods xmlns="http://www.loc.gov/mods/v3">
|
485
|
+
<originInfo>
|
486
|
+
<dateIssued point="start">1800</dateIssued>
|
487
|
+
<dateIssued point="end">1900</dateIssued>
|
488
|
+
</originInfo>
|
489
|
+
</mods>
|
490
|
+
EOF
|
491
|
+
end
|
492
|
+
|
493
|
+
it 'returns the earliest year from the date range' do
|
494
|
+
expect(record.pub_year_int).to eq 1800
|
495
|
+
end
|
496
|
+
end
|
497
|
+
|
498
|
+
context 'when it has an open-ended date range' do
|
499
|
+
let(:modsxml) do
|
500
|
+
<<-EOF
|
501
|
+
<mods xmlns="http://www.loc.gov/mods/v3">
|
502
|
+
<originInfo>
|
503
|
+
<dateIssued point="start">uuuu</dateIssued>
|
504
|
+
<dateIssued point="end">1900</dateIssued>
|
505
|
+
</originInfo>
|
506
|
+
</mods>
|
507
|
+
EOF
|
508
|
+
end
|
509
|
+
|
510
|
+
it 'returns the known part of the date range' do
|
511
|
+
expect(record.pub_year_int).to eq 1900
|
512
|
+
end
|
211
513
|
end
|
212
|
-
end
|
213
514
|
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
515
|
+
context 'with BCE dates' do
|
516
|
+
let(:modsxml) do
|
517
|
+
<<-EOF
|
518
|
+
<mods xmlns="http://www.loc.gov/mods/v3">
|
519
|
+
<originInfo>
|
520
|
+
<dateIssued encoding="edtf">-0249</dateIssued>
|
521
|
+
<dateIssued encoding="edtf">-0149</dateIssued>
|
522
|
+
</originInfo>
|
523
|
+
</mods>
|
524
|
+
EOF
|
525
|
+
end
|
526
|
+
|
527
|
+
it 'returns the earliest date' do
|
528
|
+
expect(record.pub_year_int).to eq(-249)
|
529
|
+
end
|
530
|
+
end
|
531
|
+
|
532
|
+
context 'with a BCE date range' do
|
533
|
+
let(:modsxml) do
|
534
|
+
<<-EOF
|
535
|
+
<mods xmlns="http://www.loc.gov/mods/v3">
|
536
|
+
<originInfo>
|
537
|
+
<dateIssued encoding="edtf" point="start">-0249</dateIssued>
|
538
|
+
<dateIssued encoding="edtf" point="end">-0149</dateIssued>
|
539
|
+
</originInfo>
|
540
|
+
</mods>
|
541
|
+
EOF
|
542
|
+
end
|
543
|
+
|
544
|
+
it 'returns the year of the earliest date in the range' do
|
545
|
+
expect(record.pub_year_int).to eq(-249)
|
546
|
+
end
|
547
|
+
end
|
548
|
+
|
549
|
+
context 'with a qualified date' do
|
550
|
+
let(:modsxml) do
|
551
|
+
<<-EOF
|
552
|
+
<mods xmlns="http://www.loc.gov/mods/v3">
|
553
|
+
<originInfo>
|
554
|
+
<dateIssued qualifier="approximate">249</dateIssued>
|
555
|
+
</originInfo>
|
556
|
+
</mods>
|
557
|
+
EOF
|
558
|
+
end
|
559
|
+
|
560
|
+
it 'returns the date without any qualifiers' do
|
561
|
+
expect(record.pub_year_int).to eq 249
|
562
|
+
end
|
563
|
+
|
564
|
+
context 'with ignore_approximate: true' do
|
565
|
+
it 'returns nothing' do
|
566
|
+
expect(record.pub_year_int(ignore_approximate: true)).to eq nil
|
567
|
+
end
|
568
|
+
end
|
569
|
+
end
|
570
|
+
|
571
|
+
context 'with a placeholder dates' do
|
572
|
+
let(:modsxml) do
|
573
|
+
<<-EOF
|
574
|
+
<mods xmlns="http://www.loc.gov/mods/v3">
|
575
|
+
<originInfo>
|
576
|
+
<dateIssued qualifier="approximate">9999</dateIssued>
|
577
|
+
</originInfo>
|
578
|
+
</mods>
|
579
|
+
EOF
|
580
|
+
end
|
581
|
+
|
582
|
+
it 'ignores the date' do
|
583
|
+
expect(record.pub_year_int).to eq nil
|
584
|
+
end
|
227
585
|
end
|
228
586
|
end
|
229
587
|
end
|