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
@@ -0,0 +1,427 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe "Mods <subject> Element" do
6
+ context "subterms for <name> child elements of <subject> element" do
7
+ before(:all) do
8
+ @both_types_sub = mods_record("<subject>
9
+ <name type='personal'>
10
+ <namePart>Bridgens, R.P</namePart>
11
+ </name>
12
+ </subject><subject authority='lcsh'>
13
+ <name type='corporate'>
14
+ <namePart>Britton &amp; Rey.</namePart>
15
+ </name>
16
+ </subject>").subject
17
+ @pers_name_sub = mods_record("<subject>
18
+ <name type='personal' authority='ingest'>
19
+ <namePart type='family'>Edward VI , king of England, </namePart>
20
+ <displayForm>Edward VI , king of England, 1537-1553</displayForm>
21
+ </name></subject>").subject
22
+ @mult_pers_name_sub = mods_record("<subject authority='lcsh'>
23
+ <name type='personal'>
24
+ <namePart>Baker, George H</namePart>
25
+ <role>
26
+ <roleTerm type='text'>lithographer.</roleTerm>
27
+ </role>
28
+ </name>
29
+ </subject><subject>
30
+ <name type='personal'>
31
+ <namePart>Beach, Ghilion</namePart>
32
+ <role>
33
+ <roleTerm type='text'>publisher.</roleTerm>
34
+ </role>
35
+ </name>
36
+ </subject><subject>
37
+ <name type='personal'>
38
+ <namePart>Bridgens, R.P</namePart>
39
+ </name>
40
+ </subject><subject authority='lcsh'>
41
+ <name type='personal'>
42
+ <namePart>Couts, Cave Johnson</namePart>
43
+ <namePart type='date'>1821-1874</namePart>
44
+ </name>
45
+ </subject><subject authority='lcsh'>
46
+ <name type='personal'>
47
+ <namePart>Kuchel, Charles Conrad</namePart>
48
+ <namePart type='date'>b. 1820</namePart>
49
+ </name>
50
+ </subject><subject authority='lcsh'>
51
+ <name type='personal'>
52
+ <namePart>Nahl, Charles Christian</namePart>
53
+ <namePart type='date'>1818-1878</namePart>
54
+ </name>
55
+ </subject><subject authority='lcsh'>
56
+ <name type='personal'>
57
+ <namePart>Swasey, W. F. (William F.)</namePart>
58
+ </name></subject>").subject
59
+ @mult_corp_name_sub = mods_record("<subject authority='lcsh'>
60
+ <name type='corporate'>
61
+ <namePart>Britton &amp; Rey.</namePart>
62
+ </name>
63
+ </subject><subject>
64
+ <name type='corporate'>
65
+ <namePart>Gray (W. Vallance) &amp; C.B. Gifford,</namePart>
66
+ <role>
67
+ <roleTerm type='text'>lithographers.</roleTerm>
68
+ </role>
69
+ </name></subject>").subject
70
+ end
71
+ it "should be able to identify corporate names" do
72
+ expect(@both_types_sub.corporate_name.namePart.map { |e| e.text }).to eq(['Britton & Rey.'])
73
+ end
74
+ it "should be able to identify personal names" do
75
+ expect(@both_types_sub.personal_name.namePart.map { |e| e.text }).to eq(['Bridgens, R.P'])
76
+ expect(@pers_name_sub.personal_name.displayForm.map { |e| e.text }).to eq(['Edward VI , king of England, 1537-1553'])
77
+ end
78
+ it "should be able to identify roles associated with a name" do
79
+ expect(@mult_corp_name_sub.corporate_name.role.roleTerm.map { |e| e.text }).to eq(['lithographers.'])
80
+ end
81
+ it "should be able to identify dates associated with a name" do
82
+ expect(@mult_pers_name_sub.personal_name.date.map { |e| e.text }).to include("1818-1878")
83
+ end
84
+ end
85
+
86
+ before(:all) do
87
+ @four_subjects = mods_record("<subject authority='lcsh'>
88
+ <geographic>San Francisco (Calif.)</geographic>
89
+ <topic>History</topic>
90
+ <genre>Pictorial works</genre>
91
+ </subject>
92
+ <subject authority='lcsh'>
93
+ <geographic>San Diego (Calif.)</geographic>
94
+ <topic>History</topic>
95
+ <genre>Pictorial works</genre>
96
+ </subject>
97
+ <subject authority='lcsh'>
98
+ <topic>History</topic>
99
+ <genre>Pictorial works</genre>
100
+ </subject>
101
+ <subject authority='lcsh'>
102
+ <geographic>San Luis Rey (Calif.)</geographic>
103
+ <genre>Pictorial works</genre>
104
+ </subject>").subject
105
+ @geo_code_subject = mods_record("<subject>
106
+ <geographicCode authority='marcgac'>f------</geographicCode></subject>").subject
107
+ @lcsh_subject = mods_record("<subject authority='lcsh'>
108
+ <geographic>Africa</geographic>
109
+ <genre>Maps</genre>
110
+ <temporal>500-1400</temporal></subject>").subject
111
+ end
112
+
113
+ it "should be a NodeSet" do
114
+ expect(@four_subjects).to be_an_instance_of(Nokogiri::XML::NodeSet)
115
+ expect(@lcsh_subject).to be_an_instance_of(Nokogiri::XML::NodeSet)
116
+ end
117
+ it "should have as many members as there are <subject> elements in the xml" do
118
+ expect(@four_subjects.size).to eq(4)
119
+ expect(@lcsh_subject.size).to eq(1)
120
+ end
121
+ it "should recognize authority attribute on <subject> element" do
122
+ ['lcsh', 'ingest', 'lctgm'].each { |a|
123
+ expect(mods_record("<subject authority='#{a}'><topic>Ruler, English.</topic></subject>").subject.authority).to eq([a])
124
+ }
125
+ end
126
+
127
+ context "<topic> child element" do
128
+ before(:all) do
129
+ @topic_simple = mods_record(<<-XML).subject.topic
130
+ <subject authority='lcsh'><topic>History</topic>
131
+ XML
132
+
133
+ @multi_topic = mods_record(<<-XML).subject.topic
134
+ <subject>
135
+ <topic>California as an island--Maps--1662?</topic>
136
+ <topic>North America--Maps--To 1800</topic>
137
+ <topic>North America--Maps--1662?</topic>
138
+ </subject>
139
+ XML
140
+ end
141
+ it "should be a NodeSet" do
142
+ expect(@topic_simple).to be_an_instance_of(Nokogiri::XML::NodeSet)
143
+ expect(@multi_topic).to be_an_instance_of(Nokogiri::XML::NodeSet)
144
+ end
145
+ it "topic NodeSet should have as many Nodes as there are <topic> elements in the xml" do
146
+ expect(@topic_simple.size).to eq(1)
147
+ expect(@multi_topic.size).to eq(3)
148
+ expect(@four_subjects.topic.size).to eq(3)
149
+ expect(@geo_code_subject.topic.size).to eq(0)
150
+ end
151
+ it "text should get element value" do
152
+ expect(@topic_simple.text).to eq("History")
153
+ expect(@multi_topic.text).to include("California as an island--Maps--1662?")
154
+ expect(@multi_topic.text).to include("North America--Maps--To 1800")
155
+ expect(@multi_topic.text).to include("North America--Maps--1662?")
156
+ expect(@four_subjects.topic.text).to include("History")
157
+ end
158
+ end # <topic>
159
+
160
+ context "<geographic> child element" do
161
+ it "should be a NodeSet" do
162
+ expect(@four_subjects.geographic).to be_an_instance_of(Nokogiri::XML::NodeSet)
163
+ expect(@lcsh_subject.geographic).to be_an_instance_of(Nokogiri::XML::NodeSet)
164
+ expect(@geo_code_subject.geographic).to be_an_instance_of(Nokogiri::XML::NodeSet)
165
+ end
166
+ it "geographic NodeSet should have as many Nodes as there are <geographic> elements in the xml" do
167
+ expect(@four_subjects.geographic.size).to eq(3)
168
+ expect(@lcsh_subject.geographic.size).to eq(1)
169
+ expect(@geo_code_subject.geographic.size).to eq(0)
170
+ end
171
+ it "text should get element value" do
172
+ expect(@four_subjects.geographic.text).to include("San Francisco (Calif.)")
173
+ expect(@four_subjects.geographic.text).to include("San Diego (Calif.)")
174
+ expect(@four_subjects.geographic.text).to include("San Luis Rey (Calif.)")
175
+ end
176
+ it "should not include <geographicCode> element" do
177
+ expect(@geo_code_subject.geographic.size).to eq(0)
178
+ end
179
+ end # <geographic>
180
+
181
+ context "<temporal> child element" do
182
+ before(:all) do
183
+ @temporal = mods_record("<subject>
184
+ <temporal encoding='iso8601'>20010203T040506+0700</temporal>
185
+ <!-- <temporal encoding='iso8601'>197505</temporal> -->
186
+ </subject>").subject.temporal
187
+ end
188
+
189
+ it "should recognize the date attributes" do
190
+ expect(@temporal.encoding).to eq(['iso8601'])
191
+ Mods::DATE_ATTRIBS.each { |a|
192
+ expect(mods_record("<subject><temporal #{a}='val'>now</temporal></subject>").subject.temporal.send(a.to_sym)).to eq(['val'])
193
+ }
194
+ end
195
+ it "should be a NodeSet" do
196
+ expect(@lcsh_subject.temporal).to be_an_instance_of(Nokogiri::XML::NodeSet)
197
+ expect(@temporal).to be_an_instance_of(Nokogiri::XML::NodeSet)
198
+ end
199
+ it "temporal NodeSet should have as many Nodes as there are <temporal> elements in the xml" do
200
+ expect(@lcsh_subject.temporal.size).to eq(1)
201
+ expect(@temporal.size).to eq(1)
202
+ end
203
+ it "text should get element value" do
204
+ expect(@lcsh_subject.temporal.map { |n| n.text }).to eq(['500-1400'])
205
+ expect(@temporal.map { |n| n.text }).to eq(['20010203T040506+0700'])
206
+ end
207
+ end # <temporal>
208
+
209
+ context "<genre> child element" do
210
+ it "should be a NodeSet" do
211
+ expect(@lcsh_subject.genre).to be_an_instance_of(Nokogiri::XML::NodeSet)
212
+ expect(@four_subjects.genre).to be_an_instance_of(Nokogiri::XML::NodeSet)
213
+ end
214
+ it "genre NodeSet should have as many Nodes as there are <genre> elements in the xml" do
215
+ expect(@lcsh_subject.genre.size).to eq(1)
216
+ expect(@four_subjects.genre.size).to eq(4)
217
+ end
218
+ it "text should get element value" do
219
+ expect(@lcsh_subject.genre.map { |n| n.text }).to eq(['Maps'])
220
+ expect(@four_subjects.genre.map { |n| n.text }).to include("Pictorial works")
221
+ end
222
+ end # <genre>
223
+
224
+ context "<geographicCode> child element" do
225
+ it "should be a NodeSet" do
226
+ expect(@geo_code_subject.geographicCode).to be_an_instance_of(Nokogiri::XML::NodeSet)
227
+ end
228
+ it "cartographics NodeSet should have as many Nodes as there are <geographicCode> elements in the xml" do
229
+ expect(@geo_code_subject.geographicCode.size).to eq(1)
230
+ end
231
+ it "text should get element value" do
232
+ expect(@geo_code_subject.geographicCode.map { |n| n.text }).to eq(['f------'])
233
+ end
234
+ it "should recognize authority attributes" do
235
+ Mods::AUTHORITY_ATTRIBS.each { |a|
236
+ record = mods_record("<subject><geographicCode #{a}='attr_val'>f------</geographicCode></subject>")
237
+ expect(record.subject.geographicCode.send(a.to_sym)).to eq(['attr_val'])
238
+ }
239
+ end
240
+ it "should recognize the sanctioned authorities" do
241
+ Mods::Subject::GEO_CODE_AUTHORITIES.each { |a|
242
+ record = mods_record("<subject><geographicCode authority='#{a}'>f------</geographicCode></subject>")
243
+ expect(record.subject.geographicCode.authority).to eq([a])
244
+ }
245
+ end
246
+ context "translated_value convenience method" do
247
+ it "should be the translation of the code if it is a marcgac code" do
248
+ record = mods_record("<subject><geographicCode authority='marcgac'>e-er</geographicCode></subject>")
249
+ expect(record.subject.geographicCode.translated_value).to eq(["Estonia"])
250
+ end
251
+ it "should be the translation of the code if it is a marccountry code" do
252
+ record = mods_record("<subject><geographicCode authority='marccountry'>mg</geographicCode></subject>")
253
+ expect(record.subject.geographicCode.translated_value).to eq(["Madagascar"])
254
+ end
255
+ it "should be nil if the code is invalid" do
256
+ record = mods_record("<subject><geographicCode authority='marcgac'>zzz</geographicCode></subject>")
257
+ expect(record.subject.geographicCode.translated_value.size).to eq(0)
258
+ end
259
+ it "should be nil if we don't have a translation for the authority" do
260
+ record = mods_record("<subject><geographicCode authority='iso3166'>zzz</geographicCode></subject>")
261
+ expect(record.subject.geographicCode.translated_value.size).to eq(0)
262
+ end
263
+ it "should work with non-ascii characters" do
264
+ record = mods_record("<subject><geographicCode authority='marccountry'>co</geographicCode></subject>")
265
+ expect(record.subject.geographicCode.translated_value).to eq(["Curaçao"])
266
+ end
267
+ end
268
+ end # <geographicCode>
269
+
270
+ context "<titleInfo> child element" do
271
+ before(:all) do
272
+ @title_info = mods_record("<subject>
273
+ <titleInfo>
274
+ <nonSort>The</nonSort>
275
+ <title>Olympics</title>
276
+ <subTitle>a history</subTitle>
277
+ </titleInfo>
278
+ </subject>").subject.titleInfo
279
+ end
280
+ it "should understand all attributes allowed on a <titleInfo> element" do
281
+ Mods::TitleInfo::ATTRIBUTES.each { |a|
282
+ ti = mods_record("<subject><titleInfo #{a}='attr_val'>THE</titleInfo></subject>").subject.titleInfo
283
+ if (a == 'type')
284
+ expect(ti.type_at).to eq(['attr_val'])
285
+ else
286
+ expect(ti.send(a.to_sym)).to eq(['attr_val'])
287
+ end
288
+ }
289
+ end
290
+ it "should understand all immediate child elements allowed on a <titleInfo> element" do
291
+ Mods::TitleInfo::CHILD_ELEMENTS.each { |e|
292
+ expect(mods_record("<subject><titleInfo><#{e}>el_val</#{e}></titleInfo></subject>").subject.titleInfo.send(e.to_sym).text).to eq('el_val')
293
+ }
294
+ expect(@title_info.nonSort.map {|n| n.text}).to eq(["The"])
295
+ end
296
+
297
+ it "should recognize authority attribute on the <titleInfo> element" do
298
+ expect(mods_record("<subject>
299
+ <titleInfo type='uniform' authority='naf'>
300
+ <title>Missale Carnotense</title>
301
+ </titleInfo></subject>").subject.titleInfo.authority).to eq(["naf"])
302
+ end
303
+ end # <titleInfo>
304
+
305
+ context "<name> child element" do
306
+ it "should understand all attributes allowed on a <name> element" do
307
+ Mods::Name::ATTRIBUTES.each { |a|
308
+ name = mods_record("<subject><name #{a}='attr_val'>Obadiah</name></subject>").subject.name_el
309
+ if (a == 'type')
310
+ expect(name.type_at).to eq(['attr_val'])
311
+ else
312
+ expect(name.send(a.to_sym)).to eq(['attr_val'])
313
+ end
314
+ }
315
+ end
316
+ it "should understand all immediate child elements allowed on a <name> element" do
317
+ Mods::Name::CHILD_ELEMENTS.each { |e|
318
+ name = mods_record("<subject><name><#{e}>el_val</#{e}></name></subject>").subject.name_el
319
+ if (e == 'description')
320
+ expect(name.description_el.text).to eq('el_val')
321
+ elsif (e != 'role')
322
+ expect(name.send(e.to_sym).text).to eq('el_val')
323
+ end
324
+ }
325
+ end
326
+ it "should recognize authority attribute on the <name> element" do
327
+ expect(mods_record("<subject>
328
+ <name type='personal' authority='lcsh'>
329
+ <namePart>Nahl, Charles Christian</namePart>
330
+ <namePart type='date'>1818-1878</namePart>
331
+ </name>").subject.name_el.authority).to eq(["lcsh"])
332
+ end
333
+ end # <name>
334
+
335
+ context "<hiearchicalGeographic> child element" do
336
+ it "should recognize authority attributes" do
337
+ Mods::AUTHORITY_ATTRIBS.each { |a|
338
+ record = mods_record("<subject><hierarchicalGeographic #{a}='attr_val'><country>Albania</country></hierarchicalGeographic></subject>")
339
+ expect(record.subject.hierarchicalGeographic.send(a.to_sym)).to eq(['attr_val'])
340
+ }
341
+ end
342
+ it "should recognize allowed child elements" do
343
+ Mods::Subject::HIER_GEO_CHILD_ELEMENTS.each { |e|
344
+ record = mods_record("<subject><hierarchicalGeographic><#{e}>el_val</#{e}></hierarchicalGeographic></subject>")
345
+ expect(record.subject.hierarchicalGeographic.send(e.to_sym).text).to eq('el_val')
346
+ }
347
+ expect(Mods::Subject::HIER_GEO_CHILD_ELEMENTS.size).to eq(12)
348
+ end
349
+ end # <hierarchicalGeographic>
350
+
351
+ context "<cartographics> child element" do
352
+ before(:all) do
353
+ @carto_scale = mods_record("<subject>
354
+ <cartographics>
355
+ <scale>[ca.1:90,000,000], [173</scale>
356
+ </cartographics>
357
+ </subject>").subject.cartographics
358
+ @carto_empties = mods_record("<subject authority=''>
359
+ <cartographics>
360
+ <scale/>
361
+ <coordinates>W1730000 W0100000 N840000 N071000</coordinates>
362
+ <projection/>
363
+ </cartographics>
364
+ </subject>").subject.cartographics
365
+ @multi_carto = mods_record("<subject>
366
+ <cartographics>
367
+ <coordinates>W0180000 E0510000 N370000 S350000</coordinates>
368
+ </cartographics>
369
+ </subject><subject>
370
+ <cartographics>
371
+ <scale>Scale [ca. 1:50,000,000]</scale>
372
+ </cartographics>
373
+ <cartographics>
374
+ <coordinates>(W18&#xB0;--E51&#xB0;/N37&#xB0;--S35&#xB0;).</coordinates>
375
+ </cartographics>
376
+ </subject>").subject.cartographics
377
+ end
378
+ it "should be a NodeSet" do
379
+ expect(@carto_scale).to be_an_instance_of(Nokogiri::XML::NodeSet)
380
+ expect(@carto_empties).to be_an_instance_of(Nokogiri::XML::NodeSet)
381
+ expect(@multi_carto).to be_an_instance_of(Nokogiri::XML::NodeSet)
382
+ end
383
+ it "cartographics NodeSet should have as many Nodes as there are <cartographics> elements in the xml" do
384
+ expect(@carto_scale.size).to eq(1)
385
+ expect(@carto_empties.size).to eq(1)
386
+ expect(@multi_carto.size).to eq(3)
387
+ end
388
+ it "should recognize allowed child elements" do
389
+ Mods::Subject::CARTOGRAPHICS_CHILD_ELEMENTS.each { |e|
390
+ record = mods_record("<subject><cartographics><#{e}>el_val</#{e}></cartographics></subject>")
391
+ expect(record.subject.cartographics.send(e.to_sym).text).to eq('el_val')
392
+ }
393
+ expect(Mods::Subject::CARTOGRAPHICS_CHILD_ELEMENTS.size).to eq(3)
394
+ end
395
+ it "should get the number of populated <coordinates> elements for coordinates term" do
396
+ @multi_carto.coordinates.size == 2
397
+ end
398
+ it "should be able to get the value of populated elements" do
399
+ expect(@carto_scale.scale.map { |n| n.text }).to eq(['[ca.1:90,000,000], [173'])
400
+ expect(@carto_empties.coordinates.map { |n| n.text }).to eq(['W1730000 W0100000 N840000 N071000'])
401
+ end
402
+ it "should get the empty string for empty elements?" do
403
+ expect(@carto_empties.projection.map { |n| n.text }).to eq([''])
404
+ end
405
+ end # <cartographics>
406
+
407
+ context "<occupation> child element" do
408
+ before(:all) do
409
+ @occupation = mods_record("<subject><occupation>Migrant laborers</occupation>").subject.occupation
410
+ end
411
+ it "should be a NodeSet" do
412
+ expect(@occupation).to be_an_instance_of(Nokogiri::XML::NodeSet)
413
+ end
414
+ it "occupation NodeSet should have as many Nodes as there are <occupation> elements in the xml" do
415
+ expect(@occupation.size).to eq(1)
416
+ end
417
+ it "text should get element value" do
418
+ expect(@occupation.map { |n| n.text }).to eq(['Migrant laborers'])
419
+ end
420
+ it "should recognize authority attributes" do
421
+ Mods::AUTHORITY_ATTRIBS.each { |a|
422
+ record = mods_record("<subject><occupation #{a}='attr_val'>Flunkie</occupation></subject>")
423
+ expect(record.subject.occupation.send(a.to_sym)).to eq(['attr_val'])
424
+ }
425
+ end
426
+ end
427
+ end
@@ -0,0 +1,108 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Mods <titleInfo> element" do
4
+ it "should recognize type attribute on titleInfo element" do
5
+ Mods::TitleInfo::TYPES.each { |t|
6
+ record = mods_record("<titleInfo type='#{t}'>hi</titleInfo>")
7
+ expect(record.title_info.type_at).to eq([t])
8
+ }
9
+ end
10
+ it "should recognize subelements" do
11
+ Mods::TitleInfo::CHILD_ELEMENTS.each { |e|
12
+ record = mods_record("<titleInfo><#{e}>oofda</#{e}></titleInfo>")
13
+ expect(record.title_info.send(e).text).to eq('oofda')
14
+ }
15
+ end
16
+
17
+ context "short_title" do
18
+ it "should start with nonSort element" do
19
+ record = mods_record("<titleInfo><title>Jerk</title><nonSort>The</nonSort></titleInfo>")
20
+ expect(record.title_info.short_title).to eq(["The Jerk"])
21
+ end
22
+ it "should not include subtitle" do
23
+ record = mods_record("<titleInfo><title>Jerk</title><subTitle>A Tale of Tourettes</subTitle><nonSort>The</nonSort></titleInfo>")
24
+ expect(record.title_info.short_title).to eq(["The Jerk"])
25
+ end
26
+ it "Mods::Record.short_titles convenience method should return an Array (multiple titles are legal in Mods)" do
27
+ record = mods_record("<titleInfo><title>Jerk</title><nonSort>The</nonSort></titleInfo><titleInfo><title>Joke</title></titleInfo>")
28
+ expect(record.short_titles).to eq(["The Jerk", "Joke"])
29
+ end
30
+ it "should not include alternative titles" do
31
+ record = mods_record("<titleInfo type='alternative'><title>ta da!</title></titleInfo>")
32
+ expect(record.short_titles).not_to include("ta da!")
33
+ record = mods_record("<titleInfo type='alternative'><title>1</title></titleInfo><titleInfo><title>2</title></titleInfo>")
34
+ expect(record.short_titles).to eq(['2'])
35
+ end
36
+ # note that Mods::Record.short_title tests are in record_spec
37
+ end
38
+
39
+ context "full_title" do
40
+ it "should start with nonSort element" do
41
+ record = mods_record("<titleInfo><title>Jerk</title><nonSort>The</nonSort></titleInfo>")
42
+ expect(record.title_info.full_title).to eq(["The Jerk"])
43
+ end
44
+ it "should include subtitle" do
45
+ record = mods_record("<titleInfo><title>Jerk</title><subTitle>A Tale of Tourettes</subTitle><nonSort>The</nonSort></titleInfo>")
46
+ expect(record.title_info.full_title).to eq(["The Jerk A Tale of Tourettes"])
47
+ end
48
+ it "Mods::Record.full_titles convenience method should return an Array (multiple titles are legal in Mods)" do
49
+ record = mods_record("<titleInfo><title>Jerk</title><nonSort>The</nonSort></titleInfo><titleInfo><title>Joke</title></titleInfo>")
50
+ expect(record.full_titles).to eq(["The Jerk", "Joke"])
51
+ end
52
+ # note that Mods::Record.full_title tests are in record_spec
53
+ end
54
+
55
+ context "sort_title" do
56
+ it "should skip nonSort element" do
57
+ record = mods_record("<titleInfo><title>Jerk</title><nonSort>The</nonSort></titleInfo>")
58
+ expect(record.title_info.sort_title).to eq(["Jerk"])
59
+ end
60
+ it "should contain title and subtitle" do
61
+ record = mods_record("<titleInfo><title>Jerk</title><subTitle>A Tale of Tourettes</subTitle><nonSort>The</nonSort></titleInfo>")
62
+ expect(record.title_info.sort_title).to eq(["Jerk A Tale of Tourettes"])
63
+ end
64
+ it "should be an alternative title if there are no other choices" do
65
+ record = mods_record("<titleInfo type='alternative'><title>1</title></titleInfo>")
66
+ expect(record.title_info.sort_title).to eq(['1'])
67
+ end
68
+ it "should not be an alternative title if there are other choices" do
69
+ record = mods_record("<titleInfo type='alternative'><title>1</title></titleInfo><titleInfo><title>2</title></titleInfo>")
70
+ expect(record.title_info.sort_title).to eq(['2'])
71
+ expect(record.sort_title).to eq('2')
72
+ end
73
+ it "should have a configurable delimiter between title and subtitle" do
74
+ m = Mods::Record.new(' : ')
75
+ m.from_str("<mods xmlns='#{Mods::MODS_NS}'><titleInfo><title>Jerk</title><subTitle>A Tale of Tourettes</subTitle><nonSort>The</nonSort></titleInfo></mods>")
76
+ expect(m.title_info.sort_title).to eq(["Jerk : A Tale of Tourettes"])
77
+ end
78
+ context "Mods::Record.sort_title convenience method" do
79
+ it "convenience method sort_title in Mods::Record should return a string" do
80
+ record = mods_record("<titleInfo><title>Jerk</title><subTitle>A Tale of Tourettes</subTitle><nonSort>The</nonSort></titleInfo>")
81
+ expect(record.sort_title).to eq("Jerk A Tale of Tourettes")
82
+ end
83
+ end
84
+ # note that Mods::Record.sort_title tests are in record_spec
85
+ end
86
+
87
+ context "alternative_title" do
88
+ it "should get an alternative title, if it exists" do
89
+ record = mods_record("<titleInfo type='alternative'><title>ta da!</title></titleInfo>")
90
+ expect(record.title_info.alternative_title).to eq(["ta da!"])
91
+ end
92
+ it "Mods::Record.alternative_titles convenience method for getting an Array of alternative titles when there are multiple elements" do
93
+ record = mods_record("<titleInfo type='alternative'><title>1</title></titleInfo><titleInfo type='alternative'><title>2</title></titleInfo>")
94
+ expect(record.alternative_titles).to eq(['1', '2'])
95
+ record = mods_record("<titleInfo type='alternative'><title>1</title><title>2</title></titleInfo>")
96
+ expect(record.alternative_titles).to eq(['12'])
97
+ end
98
+ it "should not get an alternative title if type attribute is absent from titleInfo" do
99
+ record = mods_record("<titleInfo><title>ta da!</title></titleInfo>")
100
+ expect(record.alternative_titles).to eq([])
101
+ end
102
+ it "should not get an alternative title if type attribute from titleInfo is not 'alternative'" do
103
+ record = mods_record("<titleInfo type='uniform'><title>ta da!</title></titleInfo>")
104
+ expect(record.alternative_titles).to eq([])
105
+ end
106
+ # note that Mods::Record.alternative_title tests are in record_spec
107
+ end
108
+ end