mods 2.4.1 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +24 -0
  3. data/.gitignore +1 -0
  4. data/README.md +0 -1
  5. data/lib/mods/date.rb +54 -17
  6. data/lib/mods/marc_country_codes.rb +12 -10
  7. data/lib/mods/nom_terminology.rb +109 -845
  8. data/lib/mods/reader.rb +9 -39
  9. data/lib/mods/record.rb +13 -28
  10. data/lib/mods/version.rb +1 -1
  11. data/mods.gemspec +2 -2
  12. data/spec/fixture_data/hp566jq8781.xml +334 -0
  13. data/spec/integration/parker_spec.rb +217 -0
  14. data/spec/{date_spec.rb → lib/date_spec.rb} +9 -1
  15. data/spec/lib/language_spec.rb +123 -0
  16. data/spec/lib/location_spec.rb +175 -0
  17. data/spec/lib/name_spec.rb +368 -0
  18. data/spec/lib/origin_info_spec.rb +134 -0
  19. data/spec/lib/part_spec.rb +162 -0
  20. data/spec/lib/physical_description_spec.rb +72 -0
  21. data/spec/{reader_spec.rb → lib/reader_spec.rb} +1 -41
  22. data/spec/lib/record_info_spec.rb +114 -0
  23. data/spec/lib/record_spec.rb +287 -0
  24. data/spec/lib/related_item_spec.rb +124 -0
  25. data/spec/lib/subject_spec.rb +427 -0
  26. data/spec/lib/title_spec.rb +108 -0
  27. data/spec/lib/top_level_elmnts_simple_spec.rb +169 -0
  28. data/spec/spec_helper.rb +86 -5
  29. data/spec/support/fixtures.rb +9 -0
  30. metadata +49 -44
  31. data/.travis.yml +0 -16
  32. data/spec/language_spec.rb +0 -118
  33. data/spec/location_spec.rb +0 -295
  34. data/spec/name_spec.rb +0 -759
  35. data/spec/origin_info_spec.rb +0 -447
  36. data/spec/part_spec.rb +0 -471
  37. data/spec/physical_description_spec.rb +0 -144
  38. data/spec/record_info_spec.rb +0 -493
  39. data/spec/record_spec.rb +0 -356
  40. data/spec/related_item_spec.rb +0 -305
  41. data/spec/subject_spec.rb +0 -809
  42. data/spec/title_spec.rb +0 -226
  43. data/spec/top_level_elmnts_simple_spec.rb +0 -369
data/spec/subject_spec.rb DELETED
@@ -1,809 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require 'spec_helper'
4
-
5
- describe "Mods <subject> Element" do
6
- before(:all) do
7
- @mods_rec = Mods::Record.new
8
- @ns_decl = "xmlns='#{Mods::MODS_NS}'"
9
- end
10
-
11
- it "should do something intelligent with duplicate values" do
12
- skip "to be implemented"
13
- end
14
-
15
- it "should do some date parsing of temporal element based on encoding" do
16
- skip "to be implemented"
17
- end
18
-
19
- it "authority designation on the <subject> element should trickle down to child elements" do
20
- skip "to be implemented"
21
- end
22
-
23
- it "should subject personal name dates should be cleaned up???" do
24
- skip "to be implemented"
25
- end
26
-
27
- context "subterms for <name> child elements of <subject> element" do
28
- before(:all) do
29
- @both_types_sub = @mods_rec.from_str("<mods #{@ns_decl}><subject>
30
- <name type='personal'>
31
- <namePart>Bridgens, R.P</namePart>
32
- </name>
33
- </subject><subject authority='lcsh'>
34
- <name type='corporate'>
35
- <namePart>Britton &amp; Rey.</namePart>
36
- </name>
37
- </subject></mods>").subject
38
- @pers_name_sub = @mods_rec.from_str("<mods #{@ns_decl}><subject>
39
- <name type='personal' authority='ingest'>
40
- <namePart type='family'>Edward VI , king of England, </namePart>
41
- <displayForm>Edward VI , king of England, 1537-1553</displayForm>
42
- </name></subject></mods>").subject
43
- @mult_pers_name_sub = @mods_rec.from_str("<mods #{@ns_decl}><subject authority='lcsh'>
44
- <name type='personal'>
45
- <namePart>Baker, George H</namePart>
46
- <role>
47
- <roleTerm type='text'>lithographer.</roleTerm>
48
- </role>
49
- </name>
50
- </subject><subject>
51
- <name type='personal'>
52
- <namePart>Beach, Ghilion</namePart>
53
- <role>
54
- <roleTerm type='text'>publisher.</roleTerm>
55
- </role>
56
- </name>
57
- </subject><subject>
58
- <name type='personal'>
59
- <namePart>Bridgens, R.P</namePart>
60
- </name>
61
- </subject><subject authority='lcsh'>
62
- <name type='personal'>
63
- <namePart>Couts, Cave Johnson</namePart>
64
- <namePart type='date'>1821-1874</namePart>
65
- </name>
66
- </subject><subject authority='lcsh'>
67
- <name type='personal'>
68
- <namePart>Kuchel, Charles Conrad</namePart>
69
- <namePart type='date'>b. 1820</namePart>
70
- </name>
71
- </subject><subject authority='lcsh'>
72
- <name type='personal'>
73
- <namePart>Nahl, Charles Christian</namePart>
74
- <namePart type='date'>1818-1878</namePart>
75
- </name>
76
- </subject><subject authority='lcsh'>
77
- <name type='personal'>
78
- <namePart>Swasey, W. F. (William F.)</namePart>
79
- </name></subject></mods>").subject
80
- @mult_corp_name_sub = @mods_rec.from_str("<mods #{@ns_decl}><subject authority='lcsh'>
81
- <name type='corporate'>
82
- <namePart>Britton &amp; Rey.</namePart>
83
- </name>
84
- </subject><subject>
85
- <name type='corporate'>
86
- <namePart>Gray (W. Vallance) &amp; C.B. Gifford,</namePart>
87
- <role>
88
- <roleTerm type='text'>lithographers.</roleTerm>
89
- </role>
90
- </name></subject></mods>").subject
91
- end
92
- it "should be able to identify corporate names" do
93
- expect(@both_types_sub.corporate_name.namePart.map { |e| e.text }).to eq(['Britton & Rey.'])
94
- end
95
- it "should be able to identify personal names" do
96
- expect(@both_types_sub.personal_name.namePart.map { |e| e.text }).to eq(['Bridgens, R.P'])
97
- expect(@pers_name_sub.personal_name.displayForm.map { |e| e.text }).to eq(['Edward VI , king of England, 1537-1553'])
98
- end
99
- it "should be able to identify roles associated with a name" do
100
- expect(@mult_corp_name_sub.corporate_name.role.roleTerm.map { |e| e.text }).to eq(['lithographers.'])
101
- end
102
- it "should be able to identify dates associated with a name" do
103
- expect(@mult_pers_name_sub.personal_name.date.map { |e| e.text }).to include("1818-1878")
104
- end
105
- it "should do the appropriate thing with the role for the value of a name" do
106
- skip "name objects to be implemented"
107
- end
108
- it "should do the appropriate thing with the date for the value of a name" do
109
- skip "name objects to be implemented"
110
- end
111
- end
112
-
113
- context "basic subject terminology pieces" do
114
-
115
- context "WITH namespaces" do
116
- before(:all) do
117
- @four_subjects = @mods_rec.from_str("<mods #{@ns_decl}><subject authority='lcsh'>
118
- <geographic>San Francisco (Calif.)</geographic>
119
- <topic>History</topic>
120
- <genre>Pictorial works</genre>
121
- </subject>
122
- <subject authority='lcsh'>
123
- <geographic>San Diego (Calif.)</geographic>
124
- <topic>History</topic>
125
- <genre>Pictorial works</genre>
126
- </subject>
127
- <subject authority='lcsh'>
128
- <topic>History</topic>
129
- <genre>Pictorial works</genre>
130
- </subject>
131
- <subject authority='lcsh'>
132
- <geographic>San Luis Rey (Calif.)</geographic>
133
- <genre>Pictorial works</genre>
134
- </subject></mods>").subject
135
- @geo_code_subject = @mods_rec.from_str("<mods #{@ns_decl}><subject>
136
- <geographicCode authority='marcgac'>f------</geographicCode></subject></mods>").subject
137
- @lcsh_subject = @mods_rec.from_str("<mods #{@ns_decl}><subject authority='lcsh'>
138
- <geographic>Africa</geographic>
139
- <genre>Maps</genre>
140
- <temporal>500-1400</temporal></subject></mods>").subject
141
- end
142
-
143
- it "should be a NodeSet" do
144
- expect(@four_subjects).to be_an_instance_of(Nokogiri::XML::NodeSet)
145
- expect(@lcsh_subject).to be_an_instance_of(Nokogiri::XML::NodeSet)
146
- end
147
- it "should have as many members as there are <subject> elements in the xml" do
148
- expect(@four_subjects.size).to eq(4)
149
- expect(@lcsh_subject.size).to eq(1)
150
- end
151
- it "should recognize authority attribute on <subject> element" do
152
- ['lcsh', 'ingest', 'lctgm'].each { |a|
153
- expect(@mods_rec.from_str("<mods #{@ns_decl}><subject authority='#{a}'><topic>Ruler, English.</topic></subject></mods>").subject.authority).to eq([a])
154
- }
155
- end
156
-
157
- context "<topic> child element" do
158
- before(:all) do
159
- topic = "<mods #{@ns_decl}><subject authority='lcsh'><topic>History</topic></subject></mods>"
160
- @topic_simple = @mods_rec.from_str(topic).subject.topic
161
- multi_topic = "<mods #{@ns_decl}><subject>
162
- <topic>California as an island--Maps--1662?</topic>
163
- <topic>North America--Maps--To 1800</topic>
164
- <topic>North America--Maps--1662?</topic>
165
- </subject></mods>"
166
- @multi_topic = @mods_rec.from_str(multi_topic).subject.topic
167
- end
168
- it "should be a NodeSet" do
169
- expect(@topic_simple).to be_an_instance_of(Nokogiri::XML::NodeSet)
170
- expect(@multi_topic).to be_an_instance_of(Nokogiri::XML::NodeSet)
171
- end
172
- it "topic NodeSet should have as many Nodes as there are <topic> elements in the xml" do
173
- expect(@topic_simple.size).to eq(1)
174
- expect(@multi_topic.size).to eq(3)
175
- expect(@four_subjects.topic.size).to eq(3)
176
- expect(@geo_code_subject.topic.size).to eq(0)
177
- end
178
- it "text should get element value" do
179
- expect(@topic_simple.text).to eq("History")
180
- expect(@multi_topic.text).to include("California as an island--Maps--1662?")
181
- expect(@multi_topic.text).to include("North America--Maps--To 1800")
182
- expect(@multi_topic.text).to include("North America--Maps--1662?")
183
- expect(@four_subjects.topic.text).to include("History")
184
- end
185
- end # <topic>
186
-
187
- context "<geographic> child element" do
188
- it "should be a NodeSet" do
189
- expect(@four_subjects.geographic).to be_an_instance_of(Nokogiri::XML::NodeSet)
190
- expect(@lcsh_subject.geographic).to be_an_instance_of(Nokogiri::XML::NodeSet)
191
- expect(@geo_code_subject.geographic).to be_an_instance_of(Nokogiri::XML::NodeSet)
192
- end
193
- it "geographic NodeSet should have as many Nodes as there are <geographic> elements in the xml" do
194
- expect(@four_subjects.geographic.size).to eq(3)
195
- expect(@lcsh_subject.geographic.size).to eq(1)
196
- expect(@geo_code_subject.geographic.size).to eq(0)
197
- end
198
- it "text should get element value" do
199
- expect(@four_subjects.geographic.text).to include("San Francisco (Calif.)")
200
- expect(@four_subjects.geographic.text).to include("San Diego (Calif.)")
201
- expect(@four_subjects.geographic.text).to include("San Luis Rey (Calif.)")
202
- end
203
- it "should not include <geographicCode> element" do
204
- expect(@geo_code_subject.geographic.size).to eq(0)
205
- end
206
- end # <geographic>
207
-
208
- context "<temporal> child element" do
209
- before(:all) do
210
- @temporal = @mods_rec.from_str("<mods #{@ns_decl}><subject>
211
- <temporal encoding='iso8601'>20010203T040506+0700</temporal>
212
- <!-- <temporal encoding='iso8601'>197505</temporal> -->
213
- </subject></mods>").subject.temporal
214
- end
215
-
216
- it "should recognize the date attributes" do
217
- expect(@temporal.encoding).to eq(['iso8601'])
218
- Mods::DATE_ATTRIBS.each { |a|
219
- expect(@mods_rec.from_str("<mods #{@ns_decl}><subject><temporal #{a}='val'>now</temporal></subject></mods>").subject.temporal.send(a.to_sym)).to eq(['val'])
220
- }
221
- end
222
- it "should be a NodeSet" do
223
- expect(@lcsh_subject.temporal).to be_an_instance_of(Nokogiri::XML::NodeSet)
224
- expect(@temporal).to be_an_instance_of(Nokogiri::XML::NodeSet)
225
- end
226
- it "temporal NodeSet should have as many Nodes as there are <temporal> elements in the xml" do
227
- expect(@lcsh_subject.temporal.size).to eq(1)
228
- expect(@temporal.size).to eq(1)
229
- end
230
- it "text should get element value" do
231
- expect(@lcsh_subject.temporal.map { |n| n.text }).to eq(['500-1400'])
232
- expect(@temporal.map { |n| n.text }).to eq(['20010203T040506+0700'])
233
- end
234
- end # <temporal>
235
-
236
- context "<genre> child element" do
237
- it "should be a NodeSet" do
238
- expect(@lcsh_subject.genre).to be_an_instance_of(Nokogiri::XML::NodeSet)
239
- expect(@four_subjects.genre).to be_an_instance_of(Nokogiri::XML::NodeSet)
240
- end
241
- it "genre NodeSet should have as many Nodes as there are <genre> elements in the xml" do
242
- expect(@lcsh_subject.genre.size).to eq(1)
243
- expect(@four_subjects.genre.size).to eq(4)
244
- end
245
- it "text should get element value" do
246
- expect(@lcsh_subject.genre.map { |n| n.text }).to eq(['Maps'])
247
- expect(@four_subjects.genre.map { |n| n.text }).to include("Pictorial works")
248
- end
249
- end # <genre>
250
-
251
- context "<geographicCode> child element" do
252
- it "should be a NodeSet" do
253
- expect(@geo_code_subject.geographicCode).to be_an_instance_of(Nokogiri::XML::NodeSet)
254
- end
255
- it "cartographics NodeSet should have as many Nodes as there are <geographicCode> elements in the xml" do
256
- expect(@geo_code_subject.geographicCode.size).to eq(1)
257
- end
258
- it "text should get element value" do
259
- expect(@geo_code_subject.geographicCode.map { |n| n.text }).to eq(['f------'])
260
- end
261
- it "should recognize authority attributes" do
262
- Mods::AUTHORITY_ATTRIBS.each { |a|
263
- @mods_rec.from_str("<mods #{@ns_decl}><subject><geographicCode #{a}='attr_val'>f------</geographicCode></subject></mods>")
264
- expect(@mods_rec.subject.geographicCode.send(a.to_sym)).to eq(['attr_val'])
265
- }
266
- end
267
- it "should recognize the sanctioned authorities" do
268
- Mods::Subject::GEO_CODE_AUTHORITIES.each { |a|
269
- @mods_rec.from_str("<mods #{@ns_decl}><subject><geographicCode authority='#{a}'>f------</geographicCode></subject></mods>")
270
- expect(@mods_rec.subject.geographicCode.authority).to eq([a])
271
- }
272
- end
273
- it "should not recognize unsanctioned authorities?" do
274
- @mods_rec.from_str("<mods #{@ns_decl}><subject><geographicCode authority='fake'>f------</geographicCode></subject></mods>")
275
- skip "to be implemented"
276
- expect { @mods_rec.subject.geographicCode.authority }.to raise_error(/no idea/)
277
- end
278
- context "translated_value convenience method" do
279
- it "should be the translation of the code if it is a marcgac code" do
280
- @mods_rec.from_str("<mods #{@ns_decl}><subject><geographicCode authority='marcgac'>e-er</geographicCode></subject></mods>")
281
- expect(@mods_rec.subject.geographicCode.translated_value).to eq(["Estonia"])
282
- end
283
- it "should be the translation of the code if it is a marccountry code" do
284
- @mods_rec.from_str("<mods #{@ns_decl}><subject><geographicCode authority='marccountry'>mg</geographicCode></subject></mods>")
285
- expect(@mods_rec.subject.geographicCode.translated_value).to eq(["Madagascar"])
286
- end
287
- it "should be nil if the code is invalid" do
288
- @mods_rec.from_str("<mods #{@ns_decl}><subject><geographicCode authority='marcgac'>zzz</geographicCode></subject></mods>")
289
- expect(@mods_rec.subject.geographicCode.translated_value.size).to eq(0)
290
- end
291
- it "should be nil if we don't have a translation for the authority" do
292
- @mods_rec.from_str("<mods #{@ns_decl}><subject><geographicCode authority='iso3166'>zzz</geographicCode></subject></mods>")
293
- expect(@mods_rec.subject.geographicCode.translated_value.size).to eq(0)
294
- end
295
- it "should work with non-ascii characters" do
296
- @mods_rec.from_str("<mods #{@ns_decl}><subject><geographicCode authority='marccountry'>co</geographicCode></subject></mods>")
297
- expect(@mods_rec.subject.geographicCode.translated_value).to eq(["Curaçao"])
298
- end
299
- end
300
- end # <geographicCode>
301
-
302
- context "<titleInfo> child element" do
303
- before(:all) do
304
- @title_info = @mods_rec.from_str("<mods #{@ns_decl}><subject>
305
- <titleInfo>
306
- <nonSort>The</nonSort>
307
- <title>Olympics</title>
308
- <subTitle>a history</subTitle>
309
- </titleInfo>
310
- </subject></mods>").subject.titleInfo
311
- end
312
- it "should understand all attributes allowed on a <titleInfo> element" do
313
- Mods::TitleInfo::ATTRIBUTES.each { |a|
314
- ti = @mods_rec.from_str("<mods #{@ns_decl}><subject><titleInfo #{a}='attr_val'>THE</titleInfo></subject></mods>").subject.titleInfo
315
- if (a == 'type')
316
- expect(ti.type_at).to eq(['attr_val'])
317
- else
318
- expect(ti.send(a.to_sym)).to eq(['attr_val'])
319
- end
320
- }
321
- end
322
- it "should understand all immediate child elements allowed on a <titleInfo> element" do
323
- Mods::TitleInfo::CHILD_ELEMENTS.each { |e|
324
- expect(@mods_rec.from_str("<mods #{@ns_decl}><subject><titleInfo><#{e}>el_val</#{e}></titleInfo></subject></mods>").subject.titleInfo.send(e.to_sym).text).to eq('el_val')
325
- }
326
- expect(@title_info.nonSort.map {|n| n.text}).to eq(["The"])
327
- end
328
-
329
- it "should recognize authority attribute on the <titleInfo> element" do
330
- expect(@mods_rec.from_str("<mods #{@ns_decl}><subject>
331
- <titleInfo type='uniform' authority='naf'>
332
- <title>Missale Carnotense</title>
333
- </titleInfo></subject></mods>").subject.titleInfo.authority).to eq(["naf"])
334
- end
335
- end # <titleInfo>
336
-
337
- context "<name> child element" do
338
- it "should understand all attributes allowed on a <name> element" do
339
- Mods::Name::ATTRIBUTES.each { |a|
340
- name = @mods_rec.from_str("<mods #{@ns_decl}><subject><name #{a}='attr_val'>Obadiah</name></subject></mods>").subject.name_el
341
- if (a == 'type')
342
- expect(name.type_at).to eq(['attr_val'])
343
- else
344
- expect(name.send(a.to_sym)).to eq(['attr_val'])
345
- end
346
- }
347
- end
348
- it "should understand all immediate child elements allowed on a <name> element" do
349
- Mods::Name::CHILD_ELEMENTS.each { |e|
350
- name = @mods_rec.from_str("<mods #{@ns_decl}><subject><name><#{e}>el_val</#{e}></name></subject></mods>").subject.name_el
351
- if (e == 'description')
352
- expect(name.description_el.text).to eq('el_val')
353
- elsif (e != 'role')
354
- expect(name.send(e.to_sym).text).to eq('el_val')
355
- end
356
- }
357
- end
358
- it "should recognize authority attribute on the <name> element" do
359
- expect(@mods_rec.from_str("<mods #{@ns_decl}><subject>
360
- <name type='personal' authority='lcsh'>
361
- <namePart>Nahl, Charles Christian</namePart>
362
- <namePart type='date'>1818-1878</namePart>
363
- </name></mods>").subject.name_el.authority).to eq(["lcsh"])
364
- end
365
- end # <name>
366
-
367
- context "<hiearchicalGeographic> child element" do
368
- it "should recognize authority attributes" do
369
- Mods::AUTHORITY_ATTRIBS.each { |a|
370
- @mods_rec.from_str("<mods #{@ns_decl}><subject><hierarchicalGeographic #{a}='attr_val'><country>Albania</country></hierarchicalGeographic></subject></mods>")
371
- expect(@mods_rec.subject.hierarchicalGeographic.send(a.to_sym)).to eq(['attr_val'])
372
- }
373
- end
374
- it "should recognize allowed child elements" do
375
- Mods::Subject::HIER_GEO_CHILD_ELEMENTS.each { |e|
376
- @mods_rec.from_str("<mods #{@ns_decl}><subject><hierarchicalGeographic><#{e}>el_val</#{e}></hierarchicalGeographic></subject></mods>")
377
- expect(@mods_rec.subject.hierarchicalGeographic.send(e.to_sym).text).to eq('el_val')
378
- }
379
- expect(Mods::Subject::HIER_GEO_CHILD_ELEMENTS.size).to eq(12)
380
- end
381
- end # <hierarchicalGeographic>
382
-
383
- context "<cartographics> child element" do
384
- before(:all) do
385
- @carto_scale = @mods_rec.from_str("<mods #{@ns_decl}><subject>
386
- <cartographics>
387
- <scale>[ca.1:90,000,000], [173</scale>
388
- </cartographics>
389
- </subject></mods>").subject.cartographics
390
- @carto_empties = @mods_rec.from_str("<mods #{@ns_decl}><subject authority=''>
391
- <cartographics>
392
- <scale/>
393
- <coordinates>W1730000 W0100000 N840000 N071000</coordinates>
394
- <projection/>
395
- </cartographics>
396
- </subject></mods>").subject.cartographics
397
- @multi_carto = @mods_rec.from_str("<mods #{@ns_decl}><subject>
398
- <cartographics>
399
- <coordinates>W0180000 E0510000 N370000 S350000</coordinates>
400
- </cartographics>
401
- </subject><subject>
402
- <cartographics>
403
- <scale>Scale [ca. 1:50,000,000]</scale>
404
- </cartographics>
405
- <cartographics>
406
- <coordinates>(W18&#xB0;--E51&#xB0;/N37&#xB0;--S35&#xB0;).</coordinates>
407
- </cartographics>
408
- </subject></mods>").subject.cartographics
409
- end
410
- it "should be a NodeSet" do
411
- expect(@carto_scale).to be_an_instance_of(Nokogiri::XML::NodeSet)
412
- expect(@carto_empties).to be_an_instance_of(Nokogiri::XML::NodeSet)
413
- expect(@multi_carto).to be_an_instance_of(Nokogiri::XML::NodeSet)
414
- end
415
- it "cartographics NodeSet should have as many Nodes as there are <cartographics> elements in the xml" do
416
- expect(@carto_scale.size).to eq(1)
417
- expect(@carto_empties.size).to eq(1)
418
- expect(@multi_carto.size).to eq(3)
419
- end
420
- it "should recognize allowed child elements" do
421
- Mods::Subject::CARTOGRAPHICS_CHILD_ELEMENTS.each { |e|
422
- @mods_rec.from_str("<mods #{@ns_decl}><subject><cartographics><#{e}>el_val</#{e}></cartographics></subject></mods>")
423
- expect(@mods_rec.subject.cartographics.send(e.to_sym).text).to eq('el_val')
424
- }
425
- expect(Mods::Subject::CARTOGRAPHICS_CHILD_ELEMENTS.size).to eq(3)
426
- end
427
- it "should get the number of populated <coordinates> elements for coordinates term" do
428
- @multi_carto.coordinates.size == 2
429
- end
430
- it "should be able to get the value of populated elements" do
431
- expect(@carto_scale.scale.map { |n| n.text }).to eq(['[ca.1:90,000,000], [173'])
432
- expect(@carto_empties.coordinates.map { |n| n.text }).to eq(['W1730000 W0100000 N840000 N071000'])
433
- end
434
- it "should get the empty string for empty elements?" do
435
- expect(@carto_empties.projection.map { |n| n.text }).to eq([''])
436
- end
437
- end # <cartographics>
438
-
439
- context "<occupation> child element" do
440
- before(:all) do
441
- @occupation = @mods_rec.from_str("<mods #{@ns_decl}><subject><occupation>Migrant laborers</occupation></mods>").subject.occupation
442
- end
443
- it "should be a NodeSet" do
444
- expect(@occupation).to be_an_instance_of(Nokogiri::XML::NodeSet)
445
- end
446
- it "occupation NodeSet should have as many Nodes as there are <occupation> elements in the xml" do
447
- expect(@occupation.size).to eq(1)
448
- end
449
- it "text should get element value" do
450
- expect(@occupation.map { |n| n.text }).to eq(['Migrant laborers'])
451
- end
452
- it "should recognize authority attributes" do
453
- Mods::AUTHORITY_ATTRIBS.each { |a|
454
- @mods_rec.from_str("<mods #{@ns_decl}><subject><occupation #{a}='attr_val'>Flunkie</occupation></subject></mods>")
455
- expect(@mods_rec.subject.occupation.send(a.to_sym)).to eq(['attr_val'])
456
- }
457
- end
458
- end # <occupation>
459
- end # WITH namespaces
460
-
461
- context "WITHOUT namespaces" do
462
- before(:all) do
463
- @four_subjects = @mods_rec.from_str("<mods><subject authority='lcsh'>
464
- <geographic>San Francisco (Calif.)</geographic>
465
- <topic>History</topic>
466
- <genre>Pictorial works</genre>
467
- </subject>
468
- <subject authority='lcsh'>
469
- <geographic>San Diego (Calif.)</geographic>
470
- <topic>History</topic>
471
- <genre>Pictorial works</genre>
472
- </subject>
473
- <subject authority='lcsh'>
474
- <topic>History</topic>
475
- <genre>Pictorial works</genre>
476
- </subject>
477
- <subject authority='lcsh'>
478
- <geographic>San Luis Rey (Calif.)</geographic>
479
- <genre>Pictorial works</genre>
480
- </subject></mods>", false).subject
481
- @geo_code_subject = @mods_rec.from_str("<mods><subject>
482
- <geographicCode authority='marcgac'>f------</geographicCode></subject></mods>", false).subject
483
- @lcsh_subject = @mods_rec.from_str("<mods><subject authority='lcsh'>
484
- <geographic>Africa</geographic>
485
- <genre>Maps</genre>
486
- <temporal>500-1400</temporal></subject></mods>", false).subject
487
- end
488
-
489
- it "should be a NodeSet" do
490
- expect(@four_subjects).to be_an_instance_of(Nokogiri::XML::NodeSet)
491
- expect(@lcsh_subject).to be_an_instance_of(Nokogiri::XML::NodeSet)
492
- end
493
- it "should have as many members as there are <subject> elements in the xml" do
494
- expect(@four_subjects.size).to eq(4)
495
- expect(@lcsh_subject.size).to eq(1)
496
- end
497
- it "should recognize authority attribute on <subject> element" do
498
- ['lcsh', 'ingest', 'lctgm'].each { |a|
499
- expect(@mods_rec.from_str("<mods><subject authority='#{a}'><topic>Ruler, English.</topic></subject></mods>", false).subject.authority).to eq([a])
500
- }
501
- end
502
-
503
- context "<topic> child element" do
504
- before(:all) do
505
- topic = "<mods><subject authority='lcsh'><topic>History</topic></subject></mods>"
506
- @topic_simple = @mods_rec.from_str(topic, false).subject.topic
507
- multi_topic = "<mods><subject>
508
- <topic>California as an island--Maps--1662?</topic>
509
- <topic>North America--Maps--To 1800</topic>
510
- <topic>North America--Maps--1662?</topic>
511
- </subject></mods>"
512
- @multi_topic = @mods_rec.from_str(multi_topic, false).subject.topic
513
- end
514
- it "should be a NodeSet" do
515
- expect(@topic_simple).to be_an_instance_of(Nokogiri::XML::NodeSet)
516
- expect(@multi_topic).to be_an_instance_of(Nokogiri::XML::NodeSet)
517
- end
518
- it "topic NodeSet should have as many Nodes as there are <topic> elements in the xml" do
519
- expect(@topic_simple.size).to eq(1)
520
- expect(@multi_topic.size).to eq(3)
521
- expect(@four_subjects.topic.size).to eq(3)
522
- expect(@geo_code_subject.topic.size).to eq(0)
523
- end
524
- it "text should get element value" do
525
- expect(@topic_simple.text).to eq("History")
526
- expect(@multi_topic.text).to include("California as an island--Maps--1662?")
527
- expect(@multi_topic.text).to include("North America--Maps--To 1800")
528
- expect(@multi_topic.text).to include("North America--Maps--1662?")
529
- expect(@four_subjects.topic.text).to include("History")
530
- end
531
- end # <topic>
532
-
533
- context "<geographic> child element" do
534
- it "should be a NodeSet" do
535
- expect(@four_subjects.geographic).to be_an_instance_of(Nokogiri::XML::NodeSet)
536
- expect(@lcsh_subject.geographic).to be_an_instance_of(Nokogiri::XML::NodeSet)
537
- expect(@geo_code_subject.geographic).to be_an_instance_of(Nokogiri::XML::NodeSet)
538
- end
539
- it "geographic NodeSet should have as many Nodes as there are <geographic> elements in the xml" do
540
- expect(@four_subjects.geographic.size).to eq(3)
541
- expect(@lcsh_subject.geographic.size).to eq(1)
542
- expect(@geo_code_subject.geographic.size).to eq(0)
543
- end
544
- it "text should get element value" do
545
- expect(@four_subjects.geographic.text).to include("San Francisco (Calif.)")
546
- expect(@four_subjects.geographic.text).to include("San Diego (Calif.)")
547
- expect(@four_subjects.geographic.text).to include("San Luis Rey (Calif.)")
548
- end
549
- it "should not include <geographicCode> element" do
550
- expect(@geo_code_subject.geographic.size).to eq(0)
551
- end
552
- end # <geographic>
553
-
554
- context "<temporal> child element" do
555
- before(:all) do
556
- @temporal = @mods_rec.from_str("<mods><subject>
557
- <temporal encoding='iso8601'>20010203T040506+0700</temporal>
558
- <!-- <temporal encoding='iso8601'>197505</temporal> -->
559
- </subject></mods>", false).subject.temporal
560
- end
561
-
562
- it "should recognize the date attributes" do
563
- expect(@temporal.encoding).to eq(['iso8601'])
564
- Mods::DATE_ATTRIBS.each { |a|
565
- expect(@mods_rec.from_str("<mods><subject><temporal #{a}='val'>now</temporal></subject></mods>", false).subject.temporal.send(a.to_sym)).to eq(['val'])
566
- }
567
- end
568
- it "should be a NodeSet" do
569
- expect(@lcsh_subject.temporal).to be_an_instance_of(Nokogiri::XML::NodeSet)
570
- expect(@temporal).to be_an_instance_of(Nokogiri::XML::NodeSet)
571
- end
572
- it "temporal NodeSet should have as many Nodes as there are <temporal> elements in the xml" do
573
- expect(@lcsh_subject.temporal.size).to eq(1)
574
- expect(@temporal.size).to eq(1)
575
- end
576
- it "text should get element value" do
577
- expect(@lcsh_subject.temporal.map { |n| n.text }).to eq(['500-1400'])
578
- expect(@temporal.map { |n| n.text }).to eq(['20010203T040506+0700'])
579
- end
580
- end # <temporal>
581
-
582
- context "<genre> child element" do
583
- it "should be a NodeSet" do
584
- expect(@lcsh_subject.genre).to be_an_instance_of(Nokogiri::XML::NodeSet)
585
- expect(@four_subjects.genre).to be_an_instance_of(Nokogiri::XML::NodeSet)
586
- end
587
- it "genre NodeSet should have as many Nodes as there are <genre> elements in the xml" do
588
- expect(@lcsh_subject.genre.size).to eq(1)
589
- expect(@four_subjects.genre.size).to eq(4)
590
- end
591
- it "text should get element value" do
592
- expect(@lcsh_subject.genre.map { |n| n.text }).to eq(['Maps'])
593
- expect(@four_subjects.genre.map { |n| n.text }).to include("Pictorial works")
594
- end
595
- end # <genre>
596
-
597
- context "<geographicCode> child element" do
598
- it "should be a NodeSet" do
599
- expect(@geo_code_subject.geographicCode).to be_an_instance_of(Nokogiri::XML::NodeSet)
600
- end
601
- it "cartographics NodeSet should have as many Nodes as there are <geographicCode> elements in the xml" do
602
- expect(@geo_code_subject.geographicCode.size).to eq(1)
603
- end
604
- it "text should get element value" do
605
- expect(@geo_code_subject.geographicCode.map { |n| n.text }).to eq(['f------'])
606
- end
607
- it "should recognize authority attributes" do
608
- Mods::AUTHORITY_ATTRIBS.each { |a|
609
- @mods_rec.from_str("<mods><subject><geographicCode #{a}='attr_val'>f------</geographicCode></subject></mods>", false)
610
- expect(@mods_rec.subject.geographicCode.send(a.to_sym)).to eq(['attr_val'])
611
- }
612
- end
613
- it "should recognize the sanctioned authorities" do
614
- Mods::Subject::GEO_CODE_AUTHORITIES.each { |a|
615
- @mods_rec.from_str("<mods><subject><geographicCode authority='#{a}'>f------</geographicCode></subject></mods>", false)
616
- expect(@mods_rec.subject.geographicCode.authority).to eq([a])
617
- }
618
- end
619
- it "should not recognize unsanctioned authorities?" do
620
- @mods_rec.from_str("<mods><subject><geographicCode authority='fake'>f------</geographicCode></subject></mods>", false)
621
- skip "to be implemented"
622
- expect { @mods_rec.subject.geographicCode.authority }.to raise_error(/no idea/)
623
- end
624
- context "translated_value convenience method" do
625
- it "should be the translation of the code if it is a marcgac code" do
626
- @mods_rec.from_str("<mods><subject><geographicCode authority='marcgac'>e-er</geographicCode></subject></mods>", false)
627
- expect(@mods_rec.subject.geographicCode.translated_value).to eq(["Estonia"])
628
- end
629
- it "should be the translation of the code if it is a marccountry code" do
630
- @mods_rec.from_str("<mods><subject><geographicCode authority='marccountry'>mg</geographicCode></subject></mods>", false)
631
- expect(@mods_rec.subject.geographicCode.translated_value).to eq(["Madagascar"])
632
- end
633
- it "should be empty if the code is invalid" do
634
- @mods_rec.from_str("<mods><subject><geographicCode authority='marcgac'>zzz</geographicCode></subject></mods>", false)
635
- expect(@mods_rec.subject.geographicCode.translated_value.size).to eq(0)
636
- end
637
- it "should be empty if we don't have a translation for the authority" do
638
- @mods_rec.from_str("<mods><subject><geographicCode authority='iso3166'>zzz</geographicCode></subject></mods>", false)
639
- expect(@mods_rec.subject.geographicCode.translated_value.size).to eq(0)
640
- end
641
- it "should work with non-ascii characters" do
642
- @mods_rec.from_str("<mods><subject><geographicCode authority='marccountry'>co</geographicCode></subject></mods>", false)
643
- expect(@mods_rec.subject.geographicCode.translated_value).to eq(["Curaçao"])
644
- end
645
- end
646
- end # <geographicCode>
647
-
648
- context "<titleInfo> child element" do
649
- before(:all) do
650
- @title_info = @mods_rec.from_str("<mods><subject>
651
- <titleInfo>
652
- <nonSort>The</nonSort>
653
- <title>Olympics</title>
654
- <subTitle>a history</subTitle>
655
- </titleInfo>
656
- </subject></mods>", false).subject.titleInfo
657
- end
658
- it "should understand all attributes allowed on a <titleInfo> element" do
659
- Mods::TitleInfo::ATTRIBUTES.each { |a|
660
- ti = @mods_rec.from_str("<mods><subject><titleInfo #{a}='attr_val'>THE</titleInfo></subject></mods>", false).subject.titleInfo
661
- if (a == 'type')
662
- expect(ti.type_at).to eq(['attr_val'])
663
- else
664
- expect(ti.send(a.to_sym)).to eq(['attr_val'])
665
- end
666
- }
667
- end
668
- it "should understand all immediate child elements allowed on a <titleInfo> element" do
669
- Mods::TitleInfo::CHILD_ELEMENTS.each { |e|
670
- expect(@mods_rec.from_str("<mods><subject><titleInfo><#{e}>el_val</#{e}></titleInfo></subject></mods>", false).subject.titleInfo.send(e.to_sym).text).to eq('el_val')
671
- }
672
- expect(@title_info.nonSort.map {|n| n.text}).to eq(["The"])
673
- end
674
-
675
- it "should recognize authority attribute on the <titleInfo> element" do
676
- expect(@mods_rec.from_str("<mods><subject>
677
- <titleInfo type='uniform' authority='naf'>
678
- <title>Missale Carnotense</title>
679
- </titleInfo></subject></mods>", false).subject.titleInfo.authority).to eq(["naf"])
680
- end
681
- end # <titleInfo>
682
-
683
- context "<name> child element" do
684
- it "should understand all attributes allowed on a <name> element" do
685
- Mods::Name::ATTRIBUTES.each { |a|
686
- name = @mods_rec.from_str("<mods><subject><name #{a}='attr_val'>Obadiah</name></subject></mods>", false).subject.name_el
687
- if (a == 'type')
688
- expect(name.type_at).to eq(['attr_val'])
689
- else
690
- expect(name.send(a.to_sym)).to eq(['attr_val'])
691
- end
692
- }
693
- end
694
- it "should understand all immediate child elements allowed on a <name> element" do
695
- Mods::Name::CHILD_ELEMENTS.each { |e|
696
- name = @mods_rec.from_str("<mods><subject><name><#{e}>el_val</#{e}></name></subject></mods>", false).subject.name_el
697
- if (e == 'description')
698
- expect(name.description_el.text).to eq('el_val')
699
- elsif (e != 'role')
700
- expect(name.send(e.to_sym).text).to eq('el_val')
701
- end
702
- }
703
- end
704
- it "should recognize authority attribute on the <name> element" do
705
- expect(@mods_rec.from_str("<mods><subject>
706
- <name type='personal' authority='lcsh'>
707
- <namePart>Nahl, Charles Christian</namePart>
708
- <namePart type='date'>1818-1878</namePart>
709
- </name></mods>", false).subject.name_el.authority).to eq(["lcsh"])
710
- end
711
- end # <name>
712
-
713
- context "<hiearchicalGeographic> child element" do
714
- it "should recognize authority attributes" do
715
- Mods::AUTHORITY_ATTRIBS.each { |a|
716
- @mods_rec.from_str("<mods><subject><hierarchicalGeographic #{a}='attr_val'><country>Albania</country></hierarchicalGeographic></subject></mods>", false)
717
- expect(@mods_rec.subject.hierarchicalGeographic.send(a.to_sym)).to eq(['attr_val'])
718
- }
719
- end
720
- it "should recognize allowed child elements" do
721
- Mods::Subject::HIER_GEO_CHILD_ELEMENTS.each { |e|
722
- @mods_rec.from_str("<mods><subject><hierarchicalGeographic><#{e}>el_val</#{e}></hierarchicalGeographic></subject></mods>", false)
723
- expect(@mods_rec.subject.hierarchicalGeographic.send(e.to_sym).text).to eq('el_val')
724
- }
725
- expect(Mods::Subject::HIER_GEO_CHILD_ELEMENTS.size).to eq(12)
726
- end
727
- end # <hierarchicalGeographic>
728
-
729
- context "<cartographics> child element" do
730
- before(:all) do
731
- @carto_scale = @mods_rec.from_str("<mods><subject>
732
- <cartographics>
733
- <scale>[ca.1:90,000,000], [173</scale>
734
- </cartographics>
735
- </subject></mods>", false).subject.cartographics
736
- @carto_empties = @mods_rec.from_str("<mods><subject authority=''>
737
- <cartographics>
738
- <scale/>
739
- <coordinates>W1730000 W0100000 N840000 N071000</coordinates>
740
- <projection/>
741
- </cartographics>
742
- </subject></mods>", false).subject.cartographics
743
- @multi_carto = @mods_rec.from_str("<mods><subject>
744
- <cartographics>
745
- <coordinates>W0180000 E0510000 N370000 S350000</coordinates>
746
- </cartographics>
747
- </subject><subject>
748
- <cartographics>
749
- <scale>Scale [ca. 1:50,000,000]</scale>
750
- </cartographics>
751
- <cartographics>
752
- <coordinates>(W18&#xB0;--E51&#xB0;/N37&#xB0;--S35&#xB0;).</coordinates>
753
- </cartographics>
754
- </subject></mods>", false).subject.cartographics
755
- end
756
- it "should be a NodeSet" do
757
- expect(@carto_scale).to be_an_instance_of(Nokogiri::XML::NodeSet)
758
- expect(@carto_empties).to be_an_instance_of(Nokogiri::XML::NodeSet)
759
- expect(@multi_carto).to be_an_instance_of(Nokogiri::XML::NodeSet)
760
- end
761
- it "cartographics NodeSet should have as many Nodes as there are <cartographics> elements in the xml" do
762
- expect(@carto_scale.size).to eq(1)
763
- expect(@carto_empties.size).to eq(1)
764
- expect(@multi_carto.size).to eq(3)
765
- end
766
- it "should recognize allowed child elements" do
767
- Mods::Subject::CARTOGRAPHICS_CHILD_ELEMENTS.each { |e|
768
- @mods_rec.from_str("<mods><subject><cartographics><#{e}>el_val</#{e}></cartographics></subject></mods>", false)
769
- expect(@mods_rec.subject.cartographics.send(e.to_sym).text).to eq('el_val')
770
- }
771
- expect(Mods::Subject::CARTOGRAPHICS_CHILD_ELEMENTS.size).to eq(3)
772
- end
773
- it "should get the number of populated <coordinates> elements for coordinates term" do
774
- @multi_carto.coordinates.size == 2
775
- end
776
- it "should be able to get the value of populated elements" do
777
- expect(@carto_scale.scale.map { |n| n.text }).to eq(['[ca.1:90,000,000], [173'])
778
- expect(@carto_empties.coordinates.map { |n| n.text }).to eq(['W1730000 W0100000 N840000 N071000'])
779
- end
780
- it "should get the empty string for empty elements?" do
781
- expect(@carto_empties.projection.map { |n| n.text }).to eq([''])
782
- end
783
- end # <cartographics>
784
-
785
- context "<occupation> child element" do
786
- before(:all) do
787
- @occupation = @mods_rec.from_str("<mods><subject><occupation>Migrant laborers</occupation></mods>", false).subject.occupation
788
- end
789
- it "should be a NodeSet" do
790
- expect(@occupation).to be_an_instance_of(Nokogiri::XML::NodeSet)
791
- end
792
- it "occupation NodeSet should have as many Nodes as there are <occupation> elements in the xml" do
793
- expect(@occupation.size).to eq(1)
794
- end
795
- it "text should get element value" do
796
- expect(@occupation.map { |n| n.text }).to eq(['Migrant laborers'])
797
- end
798
- it "should recognize authority attributes" do
799
- Mods::AUTHORITY_ATTRIBS.each { |a|
800
- @mods_rec.from_str("<mods><subject><occupation #{a}='attr_val'>Flunkie</occupation></subject></mods>", false)
801
- expect(@mods_rec.subject.occupation.send(a.to_sym)).to eq(['attr_val'])
802
- }
803
- end
804
- end # <occupation>
805
- end # WITHOUT namespaces
806
-
807
- end # basic subject terminology
808
-
809
- end