stanford-mods 2.6.4 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,905 +0,0 @@
1
- # encoding: utf-8
2
- describe "date parsing methods" do
3
- unparseable = [ # here to remind us of what they might look like in our data
4
- nil,
5
- '',
6
- '[]',
7
- '?',
8
- 'uuuu',
9
- 'Aug',
10
- 'publiée le 26 germinal an VI',
11
- "l'an IVe",
12
- 'Feb',
13
- "L'AN 2 DE LA // LIBERTÉ",
14
- 'Paris',
15
- "publié en frimaire l'an 3.e de la République française",
16
- 'an 6',
17
- 'an sept',
18
- 's.n.]',
19
- 'M. D. LXI',
20
- '[An 4]',
21
- '[s.d.]',
22
- 'Undated',
23
- '1uuu'
24
- ]
25
- # example string as key, expected parsed value as value
26
- invalid_but_can_get_year = {
27
- '1966-14-14' => '1966', # 14 isn't a valid month ...
28
- '1966\4\11' => '1966', # slashes wrong way
29
- '2/31/1950' => '1950', # no 31 of Feb
30
- '1869-00-00' => '1869',
31
- '1862-01-00' => '1862',
32
- '1985-05-00' => '1985'
33
- }
34
- # example string as key, expected parsed value as value
35
- single_year = {
36
- '0700' => '0700',
37
- '0999' => '0999',
38
- '1000' => '1000',
39
- '1798' => '1798',
40
- '1583.' => '1583',
41
- '1885-' => '1885',
42
- '1644.]' => '1644',
43
- '1644]' => '1644',
44
- '1584].' => '1584',
45
- '1729?]' => '1729',
46
- '1500 CE' => '1500',
47
- '1877?' => '1877',
48
- '1797 goda' => '1797',
49
- "1616: Con licenza de'svperiori" => '1616',
50
-
51
- '[1789]' => '1789',
52
- '[1968?-' => '1968',
53
- '[1860?]' => '1860',
54
- '[1789 ?]' => '1789',
55
- '[[1790]]' => '1790',
56
- '[1579].' => '1579',
57
- '[Ca 1790]' => '1790',
58
- '[c1926]' => '1926',
59
- '[ca 1790]' => '1790',
60
- '[ca. 1790]' => '1790',
61
- '[ca. 1850?]' => '1850',
62
- '[ca.1600]' => '1600',
63
- '[after 1726]' => '1726',
64
- '[an II, i.e. 1794]' => '1794',
65
- '[approximately 1600]' => '1600',
66
- '[approximately 1558].' => '1558',
67
- '[approximately 1717?]' => '1717',
68
- '[not after 1652]' => '1652',
69
- '[not before 1543].' => '1543',
70
-
71
- "A' 1640" => '1640',
72
- 'A1566' => '1566',
73
- 'Ans. 1656' => '1656',
74
- 'Antonio Laffreri 1570' => '1570',
75
- 'An 6. 1798' => '1798',
76
- 'An 6 1798' => '1798',
77
- 'a. 1652' => '1652',
78
- 'ad decennium 1592' => '1592',
79
- 'after 1622' => '1622',
80
- 'an 10 (1802)' => '1802',
81
- 'an 14, 1805' => '1805',
82
- 'anno 1801' => '1801',
83
- 'anno 1603.' => '1603',
84
- 'approximately 1580.' => '1580',
85
- 'approximately 1700?' => '1700',
86
- 'approximately 1544]' => '1544',
87
- 'anno 1599 (v. 1).' => '1599',
88
- 'anno MDCXXXV [1635].' => '1635',
89
- 'anno dom. 1600 (v. 3).' => '1600',
90
- 'anno j65i [1651]' => '1651',
91
- 'Ca. 1580 CE' => '1580',
92
- 'c1887' => '1887',
93
- 'ca 1796]' => '1796',
94
- 'ca. 1558' => '1558',
95
- 'ca. 1560?]' => '1560',
96
- 'ca. 1700]' => '1700',
97
- 'circa 1860' => '1860',
98
- 'copyright 1855' => '1855',
99
- 'en 1788' => '1788',
100
- 'im jahr 1681' => '1681',
101
- "l'an 1.er de la Rep. 1792" => '1792',
102
- "l'anno1570" => '1570',
103
- 'MDLXXXVIII [1588]]' => '1588',
104
- 'MDLXI [1561]' => '1561',
105
- 'MDCCLII. [1752-' => '1752',
106
- 'No. 15 1792' => '1792',
107
- 's.a. [1712]' => '1712',
108
- 'publié le 24 floréal [1796]' => '1796',
109
- "Fructidor l'an 3.e [i.e. 1795]" => '1795'
110
- }
111
- # example string as key, expected parsed value as value
112
- specific_month = {
113
- '1975-05' => '1975', # vs 1918-27
114
- '1996 Jun' => '1996',
115
- 'February 1798' => '1798',
116
- 'March, 1794' => '1794',
117
- '[ ?] 10 1793' => '1793',
118
- 'agosto 1799' => '1799',
119
- 'Jan.y. thes.et 1798' => '1798',
120
- '[[décembre 1783]]' => '1783',
121
- 'im Mai 1793' => '1793',
122
- 'in Febr. 1795' => '1795',
123
- "juin année 1797" => '1797'
124
- }
125
- # example string as key, expected parsed value as value
126
- specific_day = {
127
- '1/1/1961' => '1961',
128
- '10/1/1987' => '1987',
129
- '5-1-1959' => '1959',
130
-
131
- # year first
132
- '1888-02-18' => '1888',
133
- '1966-2-5' => '1966',
134
-
135
- # text; starts with day
136
- '1 July 1799' => '1799',
137
- '1 Feb. 1782' => '1782',
138
- '15 Jan.y 1797' => '1797',
139
- '12.th May 1794' => '1794',
140
- '12th May 1794' => '1794',
141
- '12th Dec.r 1794' => '1794',
142
- '14th Feb.y 1794' => '1794',
143
- '18 Febr. 1790' => '1790',
144
- '23 Nov.r 1797' => '1797',
145
-
146
- # text; starts with year
147
- '1793 March 1st' => '1793',
148
- '1892, Jan. 1' => '1892',
149
- '1991 May 14' => '1991',
150
- '1997 Sep 6' => '1997',
151
-
152
- # text starts with words
153
- 'Boston, November 25, 1851' => '1851',
154
- 'd. 16 Feb. 1793' => '1793',
155
- 'published the 30 of June 1799' => '1799',
156
- 'Published the 1 of June 1799' => '1799',
157
- 'Pub.d Nov.r 1st 1798' => '1798',
158
- 'Published July 5th, 1784' => '1784',
159
-
160
- # text starts with month
161
- 'April 01 1797' => '1797',
162
- 'April 1 1796' => '1796',
163
- 'April 1. 1796' => '1796',
164
- 'April 16, 1632' => '1632',
165
- 'April 11th 1792' => '1792',
166
- '[April 1 1795]' => '1795',
167
-
168
- 'Aug. 1st 1797' => '1797',
169
- 'Aug 30th 1794' => '1794',
170
- 'Aug. 16 1790' => '1790',
171
- 'Aug. 20, 1883' => '1883',
172
- 'Aug. 3rd, 1886' => '1886',
173
- 'Aug.st 4 1795' => '1795',
174
- 'Aug.t 16 1794' => '1794',
175
- 'Augt. 29, 1804' => '1804',
176
- 'August 1 1794' => '1794',
177
-
178
- 'Dec. 1 1792' => '1792',
179
- 'Dec.r 1 1792' => '1792',
180
- 'Dec.r 8th 1798' => '1798',
181
- 'Decb.r 1, 1789' => '1789',
182
- 'December 16 1795' => '1795',
183
-
184
- 'Feb 12 1800' => '1800',
185
- 'Feb. 10 1798' => '1798',
186
- 'Feb. 25, 1744]' => '1744',
187
- 'Feb.ry 12 1793' => '1793',
188
- 'Feb.ry 7th 1796' => '1796',
189
- 'Feb.y 1 1794' => '1794',
190
- 'Feb.y 13th 1798' => '1798',
191
- 'Feb.y 23rd 1799' => '1799',
192
- '[Feb.y 18 1793]' => '1793',
193
-
194
- 'Jan. 1 1789' => '1789',
195
- 'Jan. 1. 1795' => '1795',
196
- 'Jan.y 15. 1795' => '1795',
197
- 'Jan.y 12st 1793' => '1793',
198
- 'Jan.y 18th 1790' => '1790',
199
-
200
- 'July 1 1796' => '1796',
201
- 'July 1. 1793' => '1793',
202
- 'July 13, 1787' => '1787',
203
- 'July 15th 1797' => '1797',
204
-
205
- 'June 1 1793' => '1793',
206
- 'June 1. 1800' => '1800',
207
- 'June1st.1805' => '1805',
208
- 'June 22, 1804' => '1804',
209
- 'July 23d 1792' => '1792',
210
- 'June 30th 1799' => '1799',
211
- '[June 2 1793]' => '1793',
212
-
213
- 'May 9, 1795' => '1795',
214
- 'May 12 1792' => '1792',
215
- 'May 21st 1798' => '1798',
216
- 'May 15th 1798' => '1798',
217
-
218
- 'Mar. 1. 1792' => '1792',
219
- 'March 1 1795' => '1795',
220
- 'March 1.t 1797' => '1797',
221
- 'March 1, 1793' => '1793',
222
- 'March 1st 1797' => '1797',
223
- 'March 6th 1798' => '1798',
224
- '[March 16 1798]' => '1798',
225
-
226
- 'Nov. 1. 1796' => '1796',
227
- 'Nov. 14th 1792' => '1792',
228
- 'Nov. 20 1789' => '1789',
229
- 'Nov.r 9, 1793' => '1793',
230
- 'Novem. 13th 1797' => '1797',
231
- 'Novembr 22nd 1794' => '1794',
232
-
233
- 'Oct 12 1792' => '1792',
234
- 'Oct 18th 1794' => '1794',
235
- 'Oct. 29 1796' => '1796',
236
- 'Oct. 11th 1794' => '1794',
237
- 'Oct.er 1st 1786' => '1786',
238
- 'Oct.r 25 1796' => '1796',
239
- 'Oct.r 25th 1794' => '1794',
240
- 'Octo.r 15 1795' => '1795',
241
-
242
- 'Sep.r 1, 1795' => '1795',
243
- 'Sep.tr 15.th 1796' => '1796',
244
- 'Sept.r 5th 1793' => '1793'
245
- }
246
- specific_day_ruby_parse_fail = {
247
- # note ruby Date.parse only handles american or euro date order, not both ??
248
- '1/30/1979' => '1979',
249
- '10/20/1976' => '1976',
250
- '5-18-2014' => '2014',
251
- # year first
252
- '1980-23-02' => '1980',
253
- '1792 20 Dec' => '1792',
254
- # text
255
- 'le 22 juin 1794' => '1794',
256
- 'mis au jour le 26 juillet 1791' => '1791',
257
- 'April 12 sd 1794' => '1794',
258
- 'Dec. 10 & 11, 1855' => '1855',
259
- 'January 22th [1800]' => '1800',
260
- 'June the 12, 1794' => '1794',
261
- 'Mai 1st 1789' => '1789',
262
- 'March 22 d. 1794' => '1794',
263
- 'N. 7 1796' => '1796',
264
- 'N[ovember] 21st 1786' => '1786',
265
- 'Oct. the 2.d 1793' => '1793'
266
- }
267
- # example string as key, expected parsed value as value
268
- specific_day_2_digit_year = {
269
- '1/2/79' => '1979',
270
- '2/12/15' => '2015',
271
- '6/11/99' => '1999',
272
- '10/1/90' => '1990',
273
- '10/21/08' => '2008',
274
- '5-1-59' => '1959',
275
- '5-1-29' => '1929',
276
- '5-1-14' => '2014'
277
- }
278
- # example string as key, expected parsed value as value
279
- multiple_years = {
280
- '1783-1788' => ['1783', '1784', '1785', '1786', '1787', '1788'],
281
- '1862-1868]' => ['1862', '1863', '1864', '1865', '1866', '1867', '1868'],
282
- '1640-1645?]' => ['1640', '1641', '1642', '1643', '1644', '1645'],
283
- '1578, 1584]' => ['1578', '1584'],
284
- '1860, [1862]' => ['1860', '1862'],
285
- '1901, c1900' => ['1901', '1900'], # pub date is one without the c,
286
- '1627 [i.e. 1646]' => ['1627', '1646'],
287
- '1698/1715' => ['1698', '1715'],
288
- '1965,1968' => ['1965', '1968'], # revs
289
- '1965|1968' => ['1965', '1968'], # revs
290
- '1789 ou 1790]' => ['1789', '1790'],
291
- '1689 [i.e. 1688-89]' => ['1689', '1688'],
292
- '1598 or 1599' => ['1598', '1599'],
293
- '1890 [c1884]' => ['1890', '1884'], # pub date is one without the c
294
- '1873,c1868' => ['1873', '1868'], # # pub date is one without the c
295
- '1872-1877 [t.5, 1874]' => ['1872', '1873', '1874', '1875', '1876', '1877'],
296
- '1809 [ca. 1810]' => ['1809', '1810'],
297
- '1726 or 1738]' => ['1726', '1738'],
298
-
299
- '[1789-1791]' => ['1789', '1790', '1791'],
300
- '[1627-1628].' => ['1627', '1628'],
301
- '[1789-1791' => ['1789', '1790', '1791'],
302
- '[1793 ou 1794]' => ['1793', '1794'],
303
- '[entre 1789 et 1791]' => ['1789', '1790', '1791'],
304
- '[Entre 1789 et 1791]' => ['1789', '1790', '1791'],
305
- '[entre 1789-1791]' => ['1789', '1790', '1791'],
306
- '[entre 1789 et 1791 ?]' => ['1789', '1790', '1791'],
307
- '[between 1882 and 1887]' => ['1882', '1883', '1884', '1885', '1886', '1887'],
308
- '[ca 1789-1791]' => ['1789', '1790', '1791'],
309
- '[ca 1790 et 1792]' => ['1790', '1791', '1792'],
310
- '[ca. 1550-1552]' => ['1550', '1551', '1552'],
311
-
312
- 'Anno 1789-1790' => ['1789', '1790'],
313
- "L'an VII de la République [1798 or 1799]" => ['1798', '1799'],
314
- 'MDCXIII [1613] (v. 1); MDLXXXIII [1583] (v. 2); and MDCVI [1606] (v. 3).' => ['1613', '1583', '1606'],
315
- 'entre 1793 et 1795' => ['1793', '1794', '1795'],
316
- 'entre 1793 et 1795]' => ['1793', '1794', '1795'],
317
- 'approximately 1600-1602.' => ['1600', '1601', '1602'],
318
- 'approximately 1650-1652]' => ['1650', '1651', '1652'],
319
- 'approximately 1643-1644.]' => ['1643', '1644'],
320
- 'ca. 1740-1745]' => ['1740', '1741', '1742', '1743', '1744', '1745'],
321
- 'circa 1851-1852' => ['1851', '1852'],
322
- 's.a. [ca. 1660, erschienen: 1782]' => ['1660', '1782'],
323
- 'view of approximately 1848, published about 1865' => ['1848', '1865']
324
- }
325
- # example string as key, expected parsed value as value
326
- multiple_years_4_digits_once = {
327
- '1918-20' => ['1918', '1919', '1920'], # vs. 1961-04
328
- '1965-8' => ['1965', '1966', '1967', '1968'], # revs
329
- '[1846-51]' => ['1846', '1847', '1848', '1849', '1850', '1851']
330
- }
331
- # example string as key, expected parsed value as value
332
- decade_only_4_digits = {
333
- 'early 1890s' => ['1890', '1891', '1892', '1893', '1894', '1895', '1896', '1897', '1898', '1899'],
334
- '1950s' => ['1950', '1951', '1952', '1953', '1954', '1955', '1956', '1957', '1958', '1959'],
335
- "1950's" => ['1950', '1951', '1952', '1953', '1954', '1955', '1956', '1957', '1958', '1959']
336
- }
337
- decade_only = {
338
- '156u' => ['1560', '1561', '1562', '1563', '1564', '1565', '1566', '1567', '1568', '1569'],
339
- '167-?]' => ['1670', '1671', '1672', '1673', '1674', '1675', '1676', '1677', '1678', '1679'],
340
- '[171-?]' => ['1710', '1711', '1712', '1713', '1714', '1715', '1716', '1717', '1718', '1719'],
341
- '[189-]' => ['1890', '1891', '1892', '1893', '1894', '1895', '1896', '1897', '1898', '1899'],
342
- 'ca.170-?]' => ['1700', '1701', '1702', '1703', '1704', '1705', '1706', '1707', '1708', '1709'],
343
- '200-?]' => ['2000', '2001', '2002', '2003', '2004', '2005', '2006', '2007', '2008', '2009'],
344
- '186?' => ['1860', '1861', '1862', '1863', '1864', '1865', '1866', '1867', '1868', '1869'],
345
- '195x' => ['1950', '1951', '1952', '1953', '1954', '1955', '1956', '1957', '1958', '1959']
346
- }
347
- century_only = {
348
- '18th century CE' => '18th century',
349
- '17uu' => '18th century',
350
- '17--?]' => '18th century',
351
- '17--]' => '18th century',
352
- '[17--]' => '18th century',
353
- '[17--?]' => '18th century'
354
- }
355
- brackets_in_middle_of_year = {
356
- '169[5]' => '1695',
357
- 'October 3, [18]91' => '1891'
358
- }
359
- # we have data like this for our Roman coins collection
360
- early_numeric_dates = {
361
- # note that values must lexically sort to create a chronological sort. (-999 before -914)
362
- '-999' => '-001',
363
- '-914' => '-086',
364
- '-18' => '-982',
365
- '-1' => '-999',
366
- '0' => '0000',
367
- '5' => '0005',
368
- '33' => '0033',
369
- '945' => '0945'
370
- }
371
- bc_dates = {
372
- # note that values must lexically sort to create a chronological sort (800 B.C. before 750 B.C.)
373
- '801 B.C.' => '-199',
374
- '800 B.C.' => '-200',
375
- '750 B.C.' => '-250',
376
- '700 B.C.' => '-300',
377
- '699 B.C.' => '-301',
378
- '75 B.C.' => '-925',
379
- '8 B.C.' => '-992'
380
- }
381
- bc_dates_to_int = {
382
- '801 B.C.' => -801,
383
- '800 B.C.' => -800,
384
- '750 B.C.' => -750,
385
- '700 B.C.' => -700,
386
- '699 B.C.' => -699,
387
- '75 B.C.' => -75,
388
- '8 B.C.' => -8
389
- }
390
-
391
- context '*date_str_for_display' do
392
- it 'calls instance method date_str_for_display' do
393
- expect_any_instance_of(Stanford::Mods::DateParsing).to receive(:date_str_for_display)
394
- Stanford::Mods::DateParsing.date_str_for_display('1666')
395
- end
396
- end
397
-
398
- context '*sortable_year_string_from_date_str' do
399
- it 'calls instance method sortable_year_string_from_date_str' do
400
- expect_any_instance_of(Stanford::Mods::DateParsing).to receive(:sortable_year_string_from_date_str)
401
- Stanford::Mods::DateParsing.sortable_year_string_from_date_str('1666')
402
- end
403
- end
404
-
405
- context '*year_int_from_date_str' do
406
- it 'calls instance method year_int_from_date_str' do
407
- expect_any_instance_of(Stanford::Mods::DateParsing).to receive(:year_int_from_date_str)
408
- Stanford::Mods::DateParsing.year_int_from_date_str('1666')
409
- end
410
- end
411
-
412
- context '#date_str_for_display' do
413
- single_year
414
- .merge(specific_month)
415
- .merge(specific_day)
416
- .merge(specific_day_2_digit_year)
417
- .merge(specific_day_ruby_parse_fail)
418
- .merge(century_only)
419
- .merge(brackets_in_middle_of_year)
420
- .merge(invalid_but_can_get_year).each do |example, expected|
421
- expected = expected.to_i.to_s if expected =~ /^\d+$/
422
- expected = "#{expected} A.D." if expected =~ /^\d{1,3}$/
423
- it "#{expected} for single value #{example}" do
424
- expect(Stanford::Mods::DateParsing.new(example).date_str_for_display).to eq expected
425
- end
426
- end
427
-
428
- decade_only
429
- .merge(decade_only_4_digits).each do |example, expected|
430
- expected = "#{expected.first.to_i}s" if expected.first =~ /^\d+$/
431
- it "#{expected} for decade #{example}" do
432
- expect(Stanford::Mods::DateParsing.new(example).date_str_for_display).to eq expected
433
- end
434
- end
435
-
436
- multiple_years
437
- .merge(multiple_years_4_digits_once).each do |example, expected|
438
- it "#{expected.first} for multi-value #{example}" do
439
- expect(Stanford::Mods::DateParsing.new(example).date_str_for_display).to eq expected.first
440
- end
441
- end
442
-
443
- early_numeric_dates.each do |example, expected|
444
- if example.start_with?('-') || example == '0'
445
- exp = "#{example[1..-1].to_i + 1} B.C."
446
- it "#{exp} for #{example}" do
447
- expect(Stanford::Mods::DateParsing.new(example).date_str_for_display).to eq exp
448
- end
449
- else
450
- expected = "#{expected.to_i} A.D." if expected =~ /^\d+$/
451
- it "#{expected} for #{example}" do
452
- expect(Stanford::Mods::DateParsing.new(example).date_str_for_display).to eq expected
453
- end
454
- end
455
- end
456
-
457
- it 'handled year "0" correctly' do
458
- expect(Stanford::Mods::DateParsing.new('0').date_str_for_display).to eq '1 B.C.'
459
- end
460
-
461
- bc_dates.keys.each do |example|
462
- it "#{example} for #{example}" do
463
- expect(Stanford::Mods::DateParsing.new(example).date_str_for_display).to eq example
464
- end
465
- end
466
- it '1600 B.C. for 1600 B.C.' do
467
- expect(Stanford::Mods::DateParsing.new('1600 B.C.').date_str_for_display).to eq '1600 B.C.'
468
- end
469
-
470
- [ # bad dates
471
- '9999',
472
- '2035',
473
- '0000-00-00',
474
- 'uuuu',
475
- '1uuu'
476
- ].each do |example|
477
- it "nil for #{example}" do
478
- expect(Stanford::Mods::DateParsing.new(example).date_str_for_display).to eq nil
479
- end
480
- end
481
- end
482
-
483
- context '#year_int_from_date_str' do
484
- single_year
485
- .merge(specific_month)
486
- .merge(specific_day)
487
- .merge(specific_day_2_digit_year)
488
- .merge(bc_dates_to_int)
489
- .merge(specific_day_ruby_parse_fail)
490
- .merge(brackets_in_middle_of_year)
491
- .merge(invalid_but_can_get_year).each do |example, expected|
492
- it "#{expected} for single value #{example}" do
493
- expect(Stanford::Mods::DateParsing.new(example).year_int_from_date_str).to eq expected.to_i
494
- end
495
- end
496
-
497
- multiple_years
498
- .merge(multiple_years_4_digits_once)
499
- .merge(decade_only)
500
- .merge(decade_only_4_digits).each do |example, expected|
501
- it "#{expected.first} for multi-value #{example}" do
502
- expect(Stanford::Mods::DateParsing.new(example).year_int_from_date_str).to eq expected.first.to_i
503
- end
504
- end
505
-
506
- century_only.keys.each do |example|
507
- it "1700 from #{example}" do
508
- expect(Stanford::Mods::DateParsing.new(example).year_int_from_date_str).to eq 1700
509
- end
510
- end
511
-
512
- early_numeric_dates.each do |example, _expected|
513
- it "#{example} for #{example}" do
514
- expect(Stanford::Mods::DateParsing.new(example).year_int_from_date_str).to eq example.to_i
515
- end
516
- end
517
-
518
- it 'nil for -1666' do
519
- skip("code broken for -yyyy dates but no existing data for this yet")
520
- expect(Stanford::Mods::DateParsing.new('-1666').year_int_from_date_str).to eq nil
521
- end
522
- it '-1666 for 1666 B.C.' do
523
- expect(Stanford::Mods::DateParsing.new('1666 B.C.').year_int_from_date_str).to eq(-1666)
524
- end
525
-
526
- [ # bad dates
527
- '9999',
528
- '2035',
529
- '0000-00-00',
530
- 'uuuu',
531
- '1uuu'
532
- ].each do |example|
533
- it "nil for #{example}" do
534
- expect(Stanford::Mods::DateParsing.new(example).year_int_from_date_str).to eq nil
535
- end
536
- end
537
- end
538
-
539
- context '#sortable_year_string_from_date_str' do
540
- single_year
541
- .merge(specific_month)
542
- .merge(specific_day)
543
- .merge(specific_day_2_digit_year)
544
- .merge(specific_day_ruby_parse_fail)
545
- .merge(early_numeric_dates)
546
- .merge(bc_dates)
547
- .merge(brackets_in_middle_of_year)
548
- .merge(invalid_but_can_get_year).each do |example, expected|
549
- it "#{expected} for single value #{example}" do
550
- expect(Stanford::Mods::DateParsing.new(example).sortable_year_string_from_date_str).to eq expected
551
- end
552
- end
553
-
554
- multiple_years
555
- .merge(multiple_years_4_digits_once)
556
- .merge(decade_only)
557
- .merge(decade_only_4_digits).each do |example, expected|
558
- it "#{expected.first} for multi-value #{example}" do
559
- expect(Stanford::Mods::DateParsing.new(example).sortable_year_string_from_date_str).to eq expected.first
560
- end
561
- end
562
-
563
- century_only.keys.each do |example|
564
- it "1700 from #{example}" do
565
- expect(Stanford::Mods::DateParsing.new(example).sortable_year_string_from_date_str).to eq '1700'
566
- end
567
- end
568
- it '0700 for 7--' do
569
- expect(Stanford::Mods::DateParsing.new('7--').sortable_year_string_from_date_str).to eq '0700'
570
- end
571
-
572
- it 'nil for 1600 B.C.' do
573
- skip "code broken for dddd B.C. but no existing data for this yet"
574
- expect(Stanford::Mods::DateParsing.new('1600 B.C.').sortable_year_string_from_date_str).to eq nil
575
- end
576
-
577
- [ # bad dates
578
- '9999',
579
- '2035',
580
- '0000-00-00',
581
- 'uuuu',
582
- '1uuu'
583
- ].each do |example|
584
- it "nil for #{example}" do
585
- expect(Stanford::Mods::DateParsing.new(example).sortable_year_string_from_date_str).to eq nil
586
- end
587
- end
588
- end
589
-
590
- context '*year_str_valid?' do
591
- { # example string as key, expected result as value
592
- '-1000' => false,
593
- '-999' => true,
594
- '-35' => true,
595
- '-3' => true,
596
- '0000' => true,
597
- '0' => true,
598
- '5' => true,
599
- '33' => true,
600
- '150' => true,
601
- (Date.today.year + 1).to_s => true, # current year + 1
602
- (Date.today.year + 2).to_s => false, # current year + 2
603
- '9999' => false,
604
- '165x' => false,
605
- '198-' => false,
606
- 'random text' => false,
607
- nil => false
608
- }.each do |example, expected|
609
- it "#{expected} for #{example}" do
610
- expect(Stanford::Mods::DateParsing.year_str_valid?(example)).to eq expected
611
- end
612
- end
613
- end
614
-
615
- context '*year_int_valid?' do
616
- { # example int as key, expected result as value
617
- -1666 => false,
618
- -999 => true,
619
- -35 => true,
620
- -3 => true,
621
- 0 => true,
622
- 5 => true,
623
- 33 => true,
624
- 150 => true,
625
- (Date.today.year + 1) => true, # current year + 1
626
- (Date.today.year + 2) => false, # current year + 2
627
- 9999 => false,
628
- '165x' => false,
629
- '198-' => false,
630
- 'random text' => false,
631
- nil => false
632
- }.each do |example, expected|
633
- it "#{expected} for #{example}" do
634
- expect(Stanford::Mods::DateParsing.year_int_valid?(example)).to eq expected
635
- end
636
- end
637
- it 'true for 0000' do
638
- expect(Stanford::Mods::DateParsing.year_int_valid?(0000)).to eq true
639
- end
640
- end
641
-
642
- context '#sortable_year_for_yyyy' do
643
- single_year
644
- .merge(specific_month)
645
- .merge(specific_day)
646
- .merge(invalid_but_can_get_year)
647
- .merge(specific_day_ruby_parse_fail).each do |example, expected|
648
- it "#{expected} for #{example}" do
649
- expect(Stanford::Mods::DateParsing.new(example).sortable_year_for_yyyy).to eq expected
650
- end
651
- end
652
-
653
- multiple_years
654
- .merge(multiple_years_4_digits_once)
655
- .merge(decade_only_4_digits).each do |example, expected|
656
- it "#{expected.first} for #{example}" do
657
- expect(Stanford::Mods::DateParsing.new(example).sortable_year_for_yyyy).to eq expected.first
658
- end
659
- end
660
-
661
- # indicate some of the strings this method cannot handle (so must be parsed with other instance methods)
662
- unparseable
663
- .push(*brackets_in_middle_of_year.keys)
664
- .push(*specific_day_2_digit_year.keys)
665
- .push(*decade_only.keys)
666
- .push(*century_only.keys).each do |example|
667
- it "nil for #{example}" do
668
- expect(Stanford::Mods::DateParsing.new(example).sortable_year_for_yyyy).to eq nil
669
- end
670
- end
671
- end
672
-
673
- context '#sortable_year_for_yy' do
674
- specific_day_2_digit_year.each do |example, expected|
675
- it "#{expected} for #{example}" do
676
- expect(Stanford::Mods::DateParsing.new(example).sortable_year_for_yy).to eq expected
677
- end
678
- end
679
- it '2000 for 12/25/00' do
680
- expect(Stanford::Mods::DateParsing.new('12/25/00').sortable_year_for_yy).to eq '2000'
681
- end
682
-
683
- # indicate some of the strings this method cannot handle (so must be parsed with other instance methods)
684
- [
685
- '92/1/31', # yy/mm/dd: doesn't work. :-(
686
- '92-31-1', # yy-dd-mm: doesn't work. :-(
687
- ].push(*decade_only.keys).each do |example|
688
- it "nil for #{example}" do
689
- expect(Stanford::Mods::DateParsing.new(example).sortable_year_for_yy).to eq nil
690
- end
691
- end
692
- end
693
-
694
- context '#sortable_year_for_decade' do
695
- decade_only.each do |example, expected|
696
- it "#{expected.first} for #{example}" do
697
- expect(Stanford::Mods::DateParsing.new(example).sortable_year_for_decade).to eq expected.first
698
- end
699
- end
700
- { # example string as key, expected result as value
701
- '199u' => '1990',
702
- '200-' => '2000',
703
- '201?' => '2010',
704
- '202x' => '2020'
705
- }.each do |example, expected|
706
- it "#{expected} for #{example}" do
707
- expect(Stanford::Mods::DateParsing.new(example).sortable_year_for_decade).to eq expected
708
- end
709
- end
710
-
711
- # some of the strings this method cannot handle (so must be parsed with other instance methods)
712
- decade_only_4_digits.keys
713
- .push(*specific_day_2_digit_year.keys).each do |example|
714
- it "nil for #{example}" do
715
- expect(Stanford::Mods::DateParsing.new(example).sortable_year_for_decade).to eq nil
716
- end
717
- end
718
- end
719
-
720
- context '#display_str_for_decade' do
721
- decade_only.each do |example, expected|
722
- it "#{expected.first} for #{example}" do
723
- expect(Stanford::Mods::DateParsing.new(example).display_str_for_decade).to eq "#{expected.first}s"
724
- end
725
- end
726
- { # example string as key, expected result as value
727
- '199u' => '1990s',
728
- '200-' => '2000s',
729
- '201?' => '2010s',
730
- '202x' => '2020s',
731
- 'early 1890s' => '1890s',
732
- '1950s' => '1950s',
733
- "1950's" => '1950s'
734
- }.each do |example, expected|
735
- it "#{expected} for #{example}" do
736
- expect(Stanford::Mods::DateParsing.new(example).display_str_for_decade).to eq expected
737
- end
738
- end
739
-
740
- # some of the strings this method cannot handle (so must be parsed with other instance methods)
741
- specific_day_2_digit_year.keys.each do |example|
742
- it "nil for #{example}" do
743
- expect(Stanford::Mods::DateParsing.new(example).display_str_for_decade).to eq nil
744
- end
745
- end
746
- end
747
-
748
- context '#sortable_year_for_century' do
749
- century_only.keys.each do |example|
750
- it "1700 from #{example}" do
751
- expect(Stanford::Mods::DateParsing.new(example).sortable_year_for_century).to eq '1700'
752
- end
753
- end
754
- it '0700 for 7--' do
755
- expect(Stanford::Mods::DateParsing.new('7--').sortable_year_for_century).to eq '0700'
756
- end
757
- it 'nil for 7th century B.C. (to be handled in different method)' do
758
- expect(Stanford::Mods::DateParsing.new('7th century B.C.').sortable_year_for_century).to eq nil
759
- end
760
- end
761
-
762
- context '#display_str_for_century' do
763
- century_only.each do |example, expected|
764
- it "#{expected} for #{example}" do
765
- expect(Stanford::Mods::DateParsing.new(example).display_str_for_century).to eq expected
766
- end
767
- end
768
- { # example string as key, expected result as value
769
- '16--' => '17th century',
770
- '7--' => '8th century',
771
- # check suffixes
772
- '20--' => '21st century',
773
- '1--' => '2nd century',
774
- '2--' => '3rd century'
775
- }.each do |example, expected|
776
- it "#{expected} for #{example}" do
777
- expect(Stanford::Mods::DateParsing.new(example).display_str_for_century).to eq expected
778
- end
779
- end
780
-
781
- it 'nil for 7th century B.C. (to be handled in different method)' do
782
- expect(Stanford::Mods::DateParsing.new('7th century B.C.').display_str_for_century).to eq nil
783
- end
784
- end
785
-
786
- context '#sortable_year_int_for_early_numeric' do
787
- early_numeric_dates.each do |example, _expected|
788
- it "#{example} for #{example}" do
789
- expect(Stanford::Mods::DateParsing.new(example).sortable_year_int_for_early_numeric).to eq example.to_i
790
- end
791
- end
792
- end
793
-
794
- context '#sortable_year_str_for_early_numeric' do
795
- early_numeric_dates.each do |example, expected|
796
- it "#{expected} for #{example}" do
797
- expect(Stanford::Mods::DateParsing.new(example).sortable_year_str_for_early_numeric).to eq expected
798
- end
799
- end
800
- end
801
-
802
- context '#display_str_for_early_numeric' do
803
- early_numeric_dates.each do |example, expected|
804
- expected = expected.to_i.to_s if expected =~ /^\d+$/
805
- if example.start_with?('-') || example == '0'
806
- exp = "#{example[1..-1].to_i + 1} B.C."
807
- it "#{exp} for #{example}" do
808
- expect(Stanford::Mods::DateParsing.new(example).display_str_for_early_numeric).to eq exp
809
- end
810
- else
811
- exp = "#{expected} A.D."
812
- it "#{expected} for #{example}" do
813
- expect(Stanford::Mods::DateParsing.new(example).display_str_for_early_numeric).to eq exp
814
- end
815
- end
816
- end
817
- end
818
-
819
- context '#sortable_year_int_for_bc' do
820
- bc_dates_to_int.each do |example, expected|
821
- it "#{expected} for #{example}" do
822
- expect(Stanford::Mods::DateParsing.new(example).sortable_year_int_for_bc).to eq expected
823
- end
824
- end
825
- end
826
-
827
- context '#sortable_year_str_for_bc' do
828
- bc_dates.each do |example, expected|
829
- it "#{expected} for #{example}" do
830
- expect(Stanford::Mods::DateParsing.new(example).sortable_year_str_for_bc).to eq expected
831
- end
832
- end
833
- end
834
-
835
- context '#display_str_for_bc' do
836
- bc_dates.keys.each do |example|
837
- it "#{example} for #{example}" do
838
- expect(Stanford::Mods::DateParsing.new(example).display_str_for_bc).to eq example
839
- end
840
- end
841
- it '1600 B.C. for 1600 B.C.' do
842
- expect(Stanford::Mods::DateParsing.new('1600 B.C.').display_str_for_bc).to eq '1600 B.C.'
843
- end
844
- end
845
-
846
- context '#year_via_ruby_parsing' do
847
- specific_day.each do |example, expected|
848
- it "#{expected} for #{example}" do
849
- expect(Stanford::Mods::DateParsing.new(example).year_via_ruby_parsing).to eq expected
850
- end
851
- end
852
-
853
- # some of the strings this method cannot handle (and must be parsed with other instance methods)
854
- multiple_years.keys
855
- .push(*multiple_years_4_digits_once.keys)
856
- .push(*decade_only_4_digits.keys)
857
- .push(*century_only.keys)
858
- .push(*invalid_but_can_get_year.keys).each do |example|
859
- it "nil for #{example}" do
860
- expect(Stanford::Mods::DateParsing.new(example).year_via_ruby_parsing).to eq nil
861
- end
862
- end
863
-
864
- # data works via #sortable_year_for_yyyy (and don't all work here):
865
- # single_year
866
- # specific_month
867
- # specific_day_ruby_parse_fail
868
-
869
- # data fails *sortable_year_for_yyyy AND for *year_via_ruby_parsing:
870
- # multiple_years
871
- # century_only
872
-
873
- # data fails *sortable_year_for_yyyy
874
- # and partially works for *year_via_ruby_parsing:
875
- skip 'parsed incorrectly' do
876
- # assigns incorrect values to 13 out of 92 (rest with no val assigned)
877
- unparseable.each do |example|
878
- it "nil for unparseable: #{example}" do
879
- expect(Stanford::Mods::DateParsing.new(example).year_via_ruby_parsing).to eq nil
880
- end
881
- end
882
-
883
- # assigns incorrect values to 2 out of 2
884
- brackets_in_middle_of_year.keys.each do |example|
885
- it "nil for brackets_in_middle_of_year: #{example}" do
886
- expect(Stanford::Mods::DateParsing.new(example).year_via_ruby_parsing).to eq nil
887
- end
888
- end
889
-
890
- # assigns incorrect values to 3 out of 8 (5 with no val assigned)
891
- specific_day_2_digit_year.keys.each do |example|
892
- it "nil for specific_day_2_digit_year: #{example}" do
893
- expect(Stanford::Mods::DateParsing.new(example).year_via_ruby_parsing).to eq nil
894
- end
895
- end
896
-
897
- # assigns incorrect values to 8 out of 8
898
- decade_only.keys.each do |example|
899
- it "nil for decade_only: #{example}" do
900
- expect(Stanford::Mods::DateParsing.new(example).year_via_ruby_parsing).to eq nil
901
- end
902
- end
903
- end
904
- end
905
- end