mods 2.4.1 → 3.0.0.alpha1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) 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/marc_country_codes.rb +12 -10
  6. data/lib/mods/nom_terminology.rb +108 -844
  7. data/lib/mods/reader.rb +9 -39
  8. data/lib/mods/record.rb +13 -28
  9. data/lib/mods/version.rb +1 -1
  10. data/mods.gemspec +2 -2
  11. data/spec/fixture_data/hp566jq8781.xml +334 -0
  12. data/spec/integration/parker_spec.rb +217 -0
  13. data/spec/{date_spec.rb → lib/date_spec.rb} +0 -0
  14. data/spec/lib/language_spec.rb +123 -0
  15. data/spec/lib/location_spec.rb +175 -0
  16. data/spec/lib/name_spec.rb +366 -0
  17. data/spec/lib/origin_info_spec.rb +134 -0
  18. data/spec/lib/part_spec.rb +162 -0
  19. data/spec/lib/physical_description_spec.rb +72 -0
  20. data/spec/{reader_spec.rb → lib/reader_spec.rb} +1 -41
  21. data/spec/lib/record_info_spec.rb +114 -0
  22. data/spec/lib/record_spec.rb +287 -0
  23. data/spec/lib/related_item_spec.rb +124 -0
  24. data/spec/lib/subject_spec.rb +427 -0
  25. data/spec/lib/title_spec.rb +108 -0
  26. data/spec/lib/top_level_elmnts_simple_spec.rb +169 -0
  27. data/spec/spec_helper.rb +86 -5
  28. data/spec/support/fixtures.rb +9 -0
  29. metadata +51 -46
  30. data/.travis.yml +0 -16
  31. data/spec/language_spec.rb +0 -118
  32. data/spec/location_spec.rb +0 -295
  33. data/spec/name_spec.rb +0 -759
  34. data/spec/origin_info_spec.rb +0 -447
  35. data/spec/part_spec.rb +0 -471
  36. data/spec/physical_description_spec.rb +0 -144
  37. data/spec/record_info_spec.rb +0 -493
  38. data/spec/record_spec.rb +0 -356
  39. data/spec/related_item_spec.rb +0 -305
  40. data/spec/subject_spec.rb +0 -809
  41. data/spec/title_spec.rb +0 -226
  42. data/spec/top_level_elmnts_simple_spec.rb +0 -369
data/spec/name_spec.rb DELETED
@@ -1,759 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "Mods <name> Element" do
4
-
5
- before(:all) do
6
- @mods_rec = Mods::Record.new
7
- @ns_decl = "xmlns='#{Mods::MODS_NS}'"
8
-
9
- @corp_name = 'ABC corp'
10
- @mods_w_corp_name_ns = "<mods #{@ns_decl}><name type='corporate'><namePart>#{@corp_name}</namePart></name></mods>"
11
- @mods_w_corp_name = @mods_w_corp_name_ns.sub(" #{@ns_decl}", '')
12
- @mods_w_corp_name_role_ns = "<mods #{@ns_decl}><name type='corporate'><namePart>#{@corp_name}</namePart>
13
- <role><roleTerm type='text'>lithographer</roleTerm></role></name></mods>"
14
- @mods_w_corp_name_role = @mods_w_corp_name_role_ns.sub(" #{@ns_decl}", '')
15
-
16
- @pers_name = 'Crusty'
17
- @mods_w_pers_name_ns = "<mods #{@ns_decl}><name type='personal'><namePart>#{@pers_name}</namePart></name></mods>"
18
- @mods_w_pers_name = @mods_w_pers_name_ns.sub(" #{@ns_decl}", '')
19
- @mods_w_both_ns = "<mods #{@ns_decl}>
20
- <name type='corporate'><namePart>#{@corp_name}</namePart></name>
21
- <name type='personal'><namePart>#{@pers_name}</namePart></name></mods>"
22
- @mods_w_both = @mods_w_both_ns.sub(" #{@ns_decl}", '')
23
-
24
- @pers_role = 'creator'
25
- @mods_w_pers_name_role_ns = "<mods #{@ns_decl}><name type='personal'><namePart>#{@pers_name}</namePart>
26
- <role><roleTerm authority='marcrelator' type='text'>#{@pers_role}</roleTerm><role></name></mods>"
27
- @mods_w_pers_name_role = @mods_w_pers_name_role_ns.sub(" #{@ns_decl}", '')
28
- @mods_w_pers_name_role_code_ns = "<mods #{@ns_decl}><name type='personal'><namePart type='given'>John</namePart>
29
- <namePart type='family'>Huston</namePart>
30
- <role>
31
- <roleTerm type='code' authority='marcrelator'>drt</roleTerm>
32
- </role>
33
- </name></mods>"
34
- @mods_w_pers_name_role_code = @mods_w_pers_name_role_code_ns.sub(" #{@ns_decl}", '')
35
- end
36
-
37
- describe "lang" do
38
- it "should have a lang attribute" do
39
- @mods_rec.from_str("<mods #{@ns_decl}><name type='personal'><namePart xml:lang='fr-FR' type='given'>Jean</namePart><namePart xml:lang='en-US' type='given'>John</namePart></name></mods>")
40
- expect(@mods_rec.personal_name.namePart.lang).to include "en-US", "fr-FR"
41
- end
42
- end
43
-
44
- context "personal name" do
45
-
46
- context "WITH namespaces" do
47
- it "should recognize child elements" do
48
- Mods::Name::CHILD_ELEMENTS.reject{|e| e == "role"}.each { |e|
49
- @mods_rec.from_str("<mods #{@ns_decl}><name type='personal'><#{e}>oofda</#{e}></name></mods>")
50
- if e == 'description'
51
- expect(@mods_rec.personal_name.description_el.text).to eq('oofda')
52
- else
53
- expect(@mods_rec.personal_name.send(e).text).to eq('oofda')
54
- end
55
- }
56
- end
57
- it "should include name elements with type attr = personal" do
58
- @mods_rec.from_str(@mods_w_pers_name_ns)
59
- expect(@mods_rec.personal_name.namePart.text).to eq(@pers_name)
60
- expect(@mods_rec.from_str(@mods_w_both_ns).personal_name.namePart.text).to eq(@pers_name)
61
- end
62
- it "should not include name elements with type attr != personal" do
63
- @mods_rec.from_str(@mods_w_corp_name_ns)
64
- expect(@mods_rec.personal_name.namePart.text).to eq("")
65
- expect(@mods_rec.from_str(@mods_w_both_ns).personal_name.namePart.text).not_to match(@corp_name)
66
- end
67
-
68
- context "roles" do
69
- it "should be possible to access a personal_name role easily" do
70
- @mods_rec.from_str(@mods_w_pers_name_role_ns)
71
- expect(@mods_rec.personal_name.role.roleTerm.text).to include(@pers_role)
72
- end
73
- it "should get role type" do
74
- @mods_rec.from_str(@mods_w_pers_name_role_ns)
75
- expect(@mods_rec.personal_name.role.roleTerm.type_at).to eq(["text"])
76
- @mods_rec.from_str(@mods_w_pers_name_role_code_ns)
77
- expect(@mods_rec.personal_name.role.roleTerm.type_at).to eq(["code"])
78
- end
79
- it "should get role authority" do
80
- @mods_rec.from_str(@mods_w_pers_name_role_ns)
81
- expect(@mods_rec.personal_name.role.roleTerm.authority).to eq(["marcrelator"])
82
- end
83
- end # roles
84
- end # WITH namespaces (personal name)
85
-
86
- context "WITHOUT namespaces" do
87
- it "should recognize child elements" do
88
- Mods::Name::CHILD_ELEMENTS.reject{|e| e == "role"}.each { |e|
89
- @mods_rec.from_str("<mods><name type='personal'><#{e}>oofda</#{e}></name></mods>", false)
90
- if e == 'description'
91
- expect(@mods_rec.personal_name.description_el.text).to eq('oofda')
92
- else
93
- expect(@mods_rec.personal_name.send(e).text).to eq('oofda')
94
- end
95
- }
96
- end
97
- it "should include name elements with type attr = personal" do
98
- @mods_rec.from_str(@mods_w_pers_name, false)
99
- expect(@mods_rec.personal_name.namePart.text).to eq(@pers_name)
100
- expect(@mods_rec.from_str(@mods_w_both, false).personal_name.namePart.text).to eq(@pers_name)
101
- end
102
- it "should not include name elements with type attr != personal" do
103
- @mods_rec.from_str(@mods_w_corp_name, false)
104
- expect(@mods_rec.personal_name.namePart.text).to eq("")
105
- expect(@mods_rec.from_str(@mods_w_both, false).personal_name.namePart.text).not_to match(@corp_name)
106
- end
107
-
108
- context "roles" do
109
- it "should be possible to access a personal_name role easily" do
110
- @mods_rec.from_str(@mods_w_pers_name_role, false)
111
- expect(@mods_rec.personal_name.role.text).to include(@pers_role)
112
- end
113
- it "should get role type" do
114
- @mods_rec.from_str(@mods_w_pers_name_role, false)
115
- expect(@mods_rec.personal_name.role.roleTerm.type_at).to eq(["text"])
116
- @mods_rec.from_str(@mods_w_pers_name_role_code, false)
117
- expect(@mods_rec.personal_name.role.roleTerm.type_at).to eq(["code"])
118
- end
119
- it "should get role authority" do
120
- @mods_rec.from_str(@mods_w_pers_name_role, false)
121
- expect(@mods_rec.personal_name.role.roleTerm.authority).to eq(["marcrelator"])
122
- end
123
- end # roles
124
- end # WITHOUT namespaces
125
-
126
- # note that Mods::Record.personal_names tests are in record_spec
127
-
128
- end # personal name
129
-
130
- context "corporate name" do
131
- context "WITH namespaces" do
132
- it "should recognize child elements" do
133
- Mods::Name::CHILD_ELEMENTS.reject{|e| e == "role" }.each { |e|
134
- @mods_rec.from_str("<mods #{@ns_decl}><name type='corporate'><#{e}>oofda</#{e}></name></mods>")
135
- if e == 'description'
136
- expect(@mods_rec.corporate_name.description_el.text).to eq('oofda')
137
- else
138
- expect(@mods_rec.corporate_name.send(e).text).to eq('oofda')
139
- end
140
- }
141
- end
142
- it "should include name elements with type attr = corporate" do
143
- @mods_rec.from_str(@mods_w_corp_name_ns)
144
- expect(@mods_rec.corporate_name.namePart.text).to eq(@corp_name)
145
- expect(@mods_rec.from_str(@mods_w_both_ns).corporate_name.namePart.text).to eq(@corp_name)
146
- end
147
- it "should not include name elements with type attr != corporate" do
148
- @mods_rec.from_str(@mods_w_pers_name_ns)
149
- expect(@mods_rec.corporate_name.namePart.text).to eq("")
150
- expect(@mods_rec.from_str(@mods_w_both_ns).corporate_name.namePart.text).not_to match(@pers_name)
151
- end
152
- end # WITH namespaces
153
- context "WITHOUT namespaces" do
154
- it "should recognize child elements" do
155
- Mods::Name::CHILD_ELEMENTS.reject{|e| e == "role" }.each { |e|
156
- @mods_rec.from_str("<mods><name type='corporate'><#{e}>oofda</#{e}></name></mods>", false)
157
- if e == 'description'
158
- expect(@mods_rec.corporate_name.description_el.text).to eq('oofda')
159
- else
160
- expect(@mods_rec.corporate_name.send(e).text).to eq('oofda')
161
- end
162
- }
163
- end
164
- it "should include name elements with type attr = corporate" do
165
- @mods_rec.from_str(@mods_w_corp_name, false)
166
- expect(@mods_rec.corporate_name.namePart.text).to eq(@corp_name)
167
- expect(@mods_rec.from_str(@mods_w_both, false).corporate_name.namePart.text).to eq(@corp_name)
168
- end
169
- it "should not include name elements with type attr != corporate" do
170
- @mods_rec.from_str(@mods_w_pers_name, false)
171
- expect(@mods_rec.corporate_name.namePart.text).to eq("")
172
- expect(@mods_rec.from_str(@mods_w_both, false).corporate_name.namePart.text).not_to match(@pers_name)
173
- end
174
- end # WITHOUT namespaces
175
-
176
- # note that Mods::Record.corporate_names tests are in record_spec
177
-
178
- end # corporate name
179
-
180
-
181
- context "(plain) <name> element terminology pieces" do
182
-
183
- context "WITH namespaces" do
184
- it "should recognize child elements" do
185
- Mods::Name::CHILD_ELEMENTS.reject{|e| e == "role"}.each { |e|
186
- @mods_rec.from_str("<mods #{@ns_decl}><name><#{e}>oofda</#{e}></name></mods>")
187
- if e == 'description'
188
- expect(@mods_rec.plain_name.description_el.text).to eq('oofda')
189
- else
190
- expect(@mods_rec.plain_name.send(e).text).to eq('oofda')
191
- end
192
- }
193
- end
194
- it "should recognize attributes on name node" do
195
- Mods::Name::ATTRIBUTES.each { |attrb|
196
- @mods_rec.from_str("<mods #{@ns_decl}><name #{attrb}='hello'><displayForm>q</displayForm></name></mods>")
197
- if attrb != 'type'
198
- expect(@mods_rec.plain_name.send(attrb)).to eq(['hello'])
199
- else
200
- expect(@mods_rec.plain_name.type_at).to eq(['hello'])
201
- end
202
- }
203
- end
204
- context "namePart child element" do
205
- it "should recognize type attribute on namePart element" do
206
- Mods::Name::NAME_PART_TYPES.each { |t|
207
- @mods_rec.from_str("<mods #{@ns_decl}><name><namePart type='#{t}'>hi</namePart></name></mods>")
208
- expect(@mods_rec.plain_name.namePart.type_at).to eq([t])
209
- }
210
- end
211
- end
212
- context "role child element" do
213
- it "should get role type" do
214
- @mods_rec.from_str(@mods_w_pers_name_role_ns)
215
- expect(@mods_rec.plain_name.role.roleTerm.type_at).to eq(["text"])
216
- @mods_rec.from_str(@mods_w_pers_name_role_code_ns)
217
- expect(@mods_rec.plain_name.role.roleTerm.type_at).to eq(["code"])
218
- end
219
- it "should get role authority" do
220
- @mods_rec.from_str(@mods_w_pers_name_role_ns)
221
- expect(@mods_rec.plain_name.role.roleTerm.authority).to eq(["marcrelator"])
222
- end
223
- end
224
-
225
- end # context WITH namespaces (plain_name)
226
-
227
- context "WITHOUT namespaces" do
228
- it "should recognize child elements" do
229
- Mods::Name::CHILD_ELEMENTS.reject{|e| e == "role"}.each { |e|
230
- @mods_rec.from_str("<mods><name><#{e}>oofda</#{e}></name></mods>", false)
231
- if e == 'description'
232
- expect(@mods_rec.plain_name.description_el.text).to eq('oofda')
233
- else
234
- expect(@mods_rec.plain_name.send(e).text).to eq('oofda')
235
- end
236
- }
237
- end
238
- it "should recognize attributes on name node" do
239
- Mods::Name::ATTRIBUTES.each { |attrb|
240
- @mods_rec.from_str("<mods><name #{attrb}='hello'><displayForm>q</displayForm></name></mods>", false)
241
- if attrb != 'type'
242
- expect(@mods_rec.plain_name.send(attrb)).to eq(['hello'])
243
- else
244
- expect(@mods_rec.plain_name.type_at).to eq(['hello'])
245
- end
246
- }
247
- end
248
- context "namePart child element" do
249
- it "should recognize type attribute on namePart element" do
250
- Mods::Name::NAME_PART_TYPES.each { |t|
251
- @mods_rec.from_str("<mods><name><namePart type='#{t}'>hi</namePart></name></mods>", false)
252
- expect(@mods_rec.plain_name.namePart.type_at).to eq([t])
253
- }
254
- end
255
- end
256
- context "role child element" do
257
- it "should get role type" do
258
- @mods_rec.from_str(@mods_w_pers_name_role, false)
259
- expect(@mods_rec.plain_name.role.roleTerm.type_at).to eq(["text"])
260
- @mods_rec.from_str(@mods_w_pers_name_role_code, false)
261
- expect(@mods_rec.plain_name.role.roleTerm.type_at).to eq(["code"])
262
- end
263
- it "should get role authority" do
264
- @mods_rec.from_str(@mods_w_pers_name_role, false)
265
- expect(@mods_rec.plain_name.role.roleTerm.authority).to eq(["marcrelator"])
266
- end
267
- end
268
- end # context WITHOUT namespaces
269
-
270
- end # plain name
271
-
272
- it "should be able to translate the marc relator code into text" do
273
- expect(MARC_RELATOR['drt']).to eq("Director")
274
- end
275
-
276
- context "display_value and display_value_w_date" do
277
- before(:all) do
278
- @disp_form = 'q'
279
- @pname1_xml = "<mods #{@ns_decl}><name type='personal'>
280
- <namePart type='given'>John</namePart>
281
- <namePart type='family'>Huston</namePart>
282
- <displayForm>#{@disp_form}</displayForm>
283
- </name></mods>"
284
- @cname_xml = "<mods #{@ns_decl}><name type='corporate'>
285
- <namePart>Watchful Eye</namePart>
286
- </name></mods>"
287
- @affl = 'affliation'
288
- @desc = 'description'
289
- @role = 'role'
290
- @name_xml = "<mods #{@ns_decl}><name>
291
- <namePart>Exciting Prints</namePart>
292
- <affiliation>#{@affl}</affiliation>
293
- <description>#{@desc}</description>
294
- <role><roleTerm type='text'>#{@role}</roleTerm></role>
295
- </name></mods>"
296
- @namepart_xml = "<mods #{@ns_decl}><name>
297
- <namePart>Suzy</namePart>
298
- <namePart type='date'>1920-</namePart>
299
- </name></mods>"
300
- end
301
- context "WITH namespaces" do
302
- before(:all) do
303
- @mods_pname1 = Mods::Record.new.from_str(@pname1_xml)
304
- @mods_cname = Mods::Record.new.from_str(@cname_xml)
305
- @mods_name = Mods::Record.new.from_str(@name_xml)
306
- @mods_namepart_date = Mods::Record.new.from_str(@namepart_xml)
307
- end
308
- it "should be a string value for each name, not an Array" do
309
- expect(@mods_name.plain_name.first.display_value).to be_an_instance_of(String)
310
- expect(@mods_name.plain_name.first.display_value_w_date).to be_an_instance_of(String)
311
- end
312
- it "should return nil when there is no display_value" do
313
- x = "<mods #{@ns_decl}><name>
314
- <namePart></namePart>
315
- </name></mods>"
316
- r = Mods::Record.new.from_str(x)
317
- expect(r.plain_name.first.display_value).to eq(nil)
318
- end
319
- it "should be applicable to all name term flavors (plain_name, personal_name, corporate_name ...)" do
320
- expect(@mods_name.plain_name.first.display_value).not_to eq(nil)
321
- expect(@mods_name.plain_name.first.display_value_w_date).not_to eq(nil)
322
- expect(@mods_pname1.personal_name.first.display_value).not_to eq(nil)
323
- expect(@mods_pname1.personal_name.first.display_value_w_date).not_to eq(nil)
324
- expect(@mods_cname.corporate_name.first.display_value).not_to eq(nil)
325
- expect(@mods_cname.corporate_name.first.display_value_w_date).not_to eq(nil)
326
- end
327
- it "should not include <affiliation> text" do
328
- expect(@mods_name.plain_name.first.display_value).not_to match(Regexp.new(@affl))
329
- end
330
- it "should not include <description> text" do
331
- expect(@mods_name.plain_name.first.display_value).not_to match(Regexp.new(@desc))
332
- end
333
- it "should not include <role> info" do
334
- expect(@mods_name.plain_name.first.display_value).not_to match(Regexp.new(@role))
335
- end
336
- it "should be the value of the <displayForm> subelement if it exists" do
337
- expect(@mods_pname1.plain_name.first.display_value).to eq(@disp_form)
338
- x = "<mods #{@ns_decl}><name type='personal'>
339
- <namePart>Alterman, Eric</namePart>
340
- <displayForm>Eric Alterman</displayForm>
341
- </name><mods>"
342
- r = Mods::Record.new.from_str(x)
343
- expect(r.plain_name.first.display_value).to eq('Eric Alterman')
344
- end
345
- it "display_value should not include <namePart type='date'>" do
346
- expect(@mods_namepart_date.plain_name.first.display_value).to eq('Suzy')
347
- end
348
- it "date text should be added to display_value_w_date when it is available" do
349
- expect(@mods_namepart_date.plain_name.first.display_value_w_date).to eq('Suzy, 1920-')
350
- end
351
- it "date text should not be added to display_value_w_dates if dates are already included" do
352
- x = "<mods #{@ns_decl}><name>
353
- <namePart>Woolf, Virginia</namePart>
354
- <namePart type='date'>1882-1941</namePart>
355
- <displayForm>Woolf, Virginia, 1882-1941</namePart>
356
- </name></mods>"
357
- r = Mods::Record.new.from_str(x)
358
- expect(r.plain_name.first.display_value_w_date).to eq('Woolf, Virginia, 1882-1941')
359
- end
360
- context "personal names" do
361
- before(:all) do
362
- @d = '1920-2005'
363
- x = "<mods #{@ns_decl}><name type='personal'>
364
- <namePart type='given'>John Paul</namePart>
365
- <namePart type='termsOfAddress'>II</namePart>
366
- <namePart type='termsOfAddress'>Pope</namePart>
367
- <namePart type='date'>#{@d}</namePart>
368
- </name></mods>"
369
- @pope = Mods::Record.new.from_str(x)
370
- x = "<mods #{@ns_decl}><name type='personal'>
371
- <namePart>Crusty</namePart>
372
- <namePart>The Clown</namePart>
373
- <namePart type='date'>#{@d}</namePart>
374
- </name></mods>"
375
- @pname2 = Mods::Record.new.from_str(x)
376
- end
377
- # use the displayForm of a personal name if present
378
- # if no displayForm, try to make a string from family name and given name "family_name, given_name"
379
- # otherwise, return all nameParts concatenated together
380
- # @return Array of Strings, each containing the above described string
381
- it "should be [family name], [given name] if they are present" do
382
- x = "<mods #{@ns_decl}><name type='personal'>
383
- <namePart type='given'>John</namePart>
384
- <namePart type='family'>Huston</namePart>
385
- </name></mods>"
386
- r = Mods::Record.new.from_str(x)
387
- expect(r.personal_name.first.display_value).to eq('Huston, John')
388
- expect(@pope.personal_name.first.display_value).to eq('John Paul II, Pope')
389
- end
390
- it "should be concatenation of untyped <namePart> elements if there is no family or given name" do
391
- expect(@pname2.personal_name.first.display_value).to eq('Crusty The Clown')
392
- end
393
- it "should include <termOfAddress> elements, in order, comma separated" do
394
- expect(@pope.personal_name.first.display_value).to eq('John Paul II, Pope')
395
- end
396
- it "display_value should not include date" do
397
- expect(@pope.personal_name.first.display_value).not_to match(Regexp.new(@d))
398
- end
399
- it "date should be included in display_value_w_date" do
400
- expect(@pope.personal_name.first.display_value_w_date).to eq("John Paul II, Pope, #{@d}")
401
- end
402
- end
403
- context "not personal name (e.g. corporate)" do
404
- it "should be the value of non-date nameParts concatenated" do
405
- x = "<mods #{@ns_decl}><name type='corporate'>
406
- <namePart>United States</namePart>
407
- <namePart>Court of Appeals (2nd Circuit)</namePart>
408
- </name></mods>"
409
- r = Mods::Record.new.from_str(x)
410
- expect(r.corporate_name.first.display_value).to eq('United States Court of Appeals (2nd Circuit)')
411
- end
412
- end
413
- end # WITH namespaces
414
-
415
- context "WITHOUT namespaces" do
416
- before(:all) do
417
- @mods_pname1 = Mods::Record.new.from_str(@pname1_xml.sub(" #{@ns_decl}", ''), false)
418
- @mods_cname = Mods::Record.new.from_str(@cname_xml.sub(" #{@ns_decl}", ''), false)
419
- @mods_name = Mods::Record.new.from_str(@name_xml.sub(" #{@ns_decl}", ''), false)
420
- @mods_namepart_date = Mods::Record.new.from_str(@namepart_xml.sub(" #{@ns_decl}", ''), false)
421
- end
422
- it "should be a string value for each name, not an Array" do
423
- expect(@mods_name.plain_name.first.display_value).to be_an_instance_of(String)
424
- expect(@mods_name.plain_name.first.display_value_w_date).to be_an_instance_of(String)
425
- end
426
- it "should return nil when there is no display_value" do
427
- x = "<mods><name>
428
- <namePart></namePart>
429
- </name></mods>"
430
- r = Mods::Record.new.from_str(x, false)
431
- expect(r.plain_name.first.display_value).to eq(nil)
432
- end
433
- it "should be applicable to all name term flavors (plain_name, personal_name, corporate_name ...)" do
434
- expect(@mods_name.plain_name.first.display_value).not_to eq(nil)
435
- expect(@mods_name.plain_name.first.display_value_w_date).not_to eq(nil)
436
- expect(@mods_pname1.personal_name.first.display_value).not_to eq(nil)
437
- expect(@mods_pname1.personal_name.first.display_value_w_date).not_to eq(nil)
438
- expect(@mods_cname.corporate_name.first.display_value).not_to eq(nil)
439
- expect(@mods_cname.corporate_name.first.display_value_w_date).not_to eq(nil)
440
- end
441
- it "should not include <affiliation> text" do
442
- expect(@mods_name.plain_name.first.display_value).not_to match(Regexp.new(@affl))
443
- end
444
- it "should not include <description> text" do
445
- expect(@mods_name.plain_name.first.display_value).not_to match(Regexp.new(@desc))
446
- end
447
- it "should not include <role> info" do
448
- expect(@mods_name.plain_name.first.display_value).not_to match(Regexp.new(@role))
449
- end
450
- it "should be the value of the <displayForm> subelement if it exists" do
451
- expect(@mods_pname1.plain_name.first.display_value).to eq(@disp_form)
452
- x = "<mods><name type='personal'>
453
- <namePart>Alterman, Eric</namePart>
454
- <displayForm>Eric Alterman</displayForm>
455
- </name><mods>"
456
- r = Mods::Record.new.from_str(x, false)
457
- expect(r.plain_name.first.display_value).to eq('Eric Alterman')
458
- end
459
- it "display_value should not include <namePart type='date'>" do
460
- expect(@mods_namepart_date.plain_name.first.display_value).to eq('Suzy')
461
- end
462
- it "date text should be added to display_value_w_date when it is available" do
463
- expect(@mods_namepart_date.plain_name.first.display_value_w_date).to eq('Suzy, 1920-')
464
- end
465
- it "date text should not be added to display_value_w_dates if dates are already included" do
466
- x = "<mods><name>
467
- <namePart>Woolf, Virginia</namePart>
468
- <namePart type='date'>1882-1941</namePart>
469
- <displayForm>Woolf, Virginia, 1882-1941</namePart>
470
- </name></mods>"
471
- r = Mods::Record.new.from_str(x, false)
472
- expect(r.plain_name.first.display_value_w_date).to eq('Woolf, Virginia, 1882-1941')
473
- end
474
- context "personal names" do
475
- before(:all) do
476
- @d = '1920-2005'
477
- x = "<mods><name type='personal'>
478
- <namePart type='given'>John Paul</namePart>
479
- <namePart type='termsOfAddress'>II</namePart>
480
- <namePart type='termsOfAddress'>Pope</namePart>
481
- <namePart type='date'>#{@d}</namePart>
482
- </name></mods>"
483
- @pope = Mods::Record.new.from_str(x, false)
484
- x = "<mods><name type='personal'>
485
- <namePart>Crusty</namePart>
486
- <namePart>The Clown</namePart>
487
- <namePart type='date'>#{@d}</namePart>
488
- </name></mods>"
489
- @pname2 = Mods::Record.new.from_str(x, false)
490
- end
491
- # use the displayForm of a personal name if present
492
- # if no displayForm, try to make a string from family name and given name "family_name, given_name"
493
- # otherwise, return all nameParts concatenated together
494
- # @return Array of Strings, each containing the above described string
495
- it "should be [family name], [given name] if they are present" do
496
- x = "<mods><name type='personal'>
497
- <namePart type='given'>John</namePart>
498
- <namePart type='family'>Huston</namePart>
499
- </name></mods>"
500
- r = Mods::Record.new.from_str(x, false)
501
- expect(r.personal_name.first.display_value).to eq('Huston, John')
502
- expect(@pope.personal_name.first.display_value).to eq('John Paul II, Pope')
503
- end
504
- it "should be concatenation of untyped <namePart> elements if there is no family or given name" do
505
- expect(@pname2.personal_name.first.display_value).to eq('Crusty The Clown')
506
- end
507
- it "should include <termOfAddress> elements, in order, comma separated" do
508
- expect(@pope.personal_name.first.display_value).to eq('John Paul II, Pope')
509
- end
510
- it "display_value should not include date" do
511
- expect(@pope.personal_name.first.display_value).not_to match(Regexp.new(@d))
512
- end
513
- it "date should be included in display_value_w_date" do
514
- expect(@pope.personal_name.first.display_value_w_date).to eq("John Paul II, Pope, #{@d}")
515
- end
516
- end
517
- context "not personal name (e.g. corporate)" do
518
- it "should be the value of non-date nameParts concatenated" do
519
- x = "<mods><name type='corporate'>
520
- <namePart>United States</namePart>
521
- <namePart>Court of Appeals (2nd Circuit)</namePart>
522
- </name></mods>"
523
- r = Mods::Record.new.from_str(x, false)
524
- expect(r.corporate_name.first.display_value).to eq('United States Court of Appeals (2nd Circuit)')
525
- end
526
- end
527
- end # WITHOUT namespaces
528
- end # display_value and display_value_w_date
529
-
530
- context "roles" do
531
- before(:all) do
532
- @xml_w_code = "<mods #{@ns_decl}><name><namePart>Alfred Hitchock</namePart>
533
- <role><roleTerm type='code' authority='marcrelator'>drt</roleTerm></role>
534
- </name></mods>"
535
- @xml_w_text = "<mods #{@ns_decl}><name><namePart>Sean Connery</namePart>
536
- <role><roleTerm type='text' authority='marcrelator'>Actor</roleTerm></role>
537
- </name></mods>"
538
- @xml_wo_authority = "<mods #{@ns_decl}><name><namePart>Exciting Prints</namePart>
539
- <role><roleTerm type='text'>lithographer</roleTerm></role>
540
- </name></mods>"
541
- @xml_w_both = "<mods #{@ns_decl}><name><namePart>anyone</namePart>
542
- <role>
543
- <roleTerm type='text' authority='marcrelator'>CreatorFake</roleTerm>
544
- <roleTerm type='code' authority='marcrelator'>cre</roleTerm>
545
- </role>
546
- </name></mods>"
547
- @xml_w_mult_roles = "<mods #{@ns_decl}><name><namePart>Fats Waller</namePart>
548
- <role><roleTerm type='text'>Creator</roleTerm>
549
- <roleTerm type='code' authority='marcrelator'>cre</roleTerm></role>
550
- <role><roleTerm type='text'>Performer</roleTerm></role>
551
- </name></mods>"
552
- end
553
-
554
- context "convenience methods WITH namespaces" do
555
- before(:all) do
556
- @mods_w_code = Mods::Record.new.from_str(@xml_w_code)
557
- @mods_w_text = Mods::Record.new.from_str(@xml_w_text)
558
- @mods_wo_authority = Mods::Record.new.from_str(@xml_wo_authority)
559
- @mods_w_both = Mods::Record.new.from_str(@xml_w_both)
560
- @mods_mult_roles = Mods::Record.new.from_str(@xml_w_mult_roles)
561
- end
562
- context "value" do
563
- it "should be the value of a text roleTerm" do
564
- expect(@mods_w_text.plain_name.role.value).to eq(["Actor"])
565
- end
566
- it "should be the translation of the code if it is a marcrelator code and there is no text roleTerm" do
567
- expect(@mods_w_code.plain_name.role.value).to eq(["Director"])
568
- end
569
- it "should be the value of the text roleTerm if there are both a code and a text roleTerm" do
570
- expect(@mods_w_both.plain_name.role.value).to eq(["CreatorFake"])
571
- end
572
- it "should have 2 values if there are 2 role elements" do
573
- expect(@mods_mult_roles.plain_name.role.value).to eq(['Creator', 'Performer'])
574
- end
575
- end
576
- context "authority" do
577
- it "should be empty if it is missing from xml" do
578
- expect(@mods_wo_authority.plain_name.role.authority.size).to eq(0)
579
- end
580
- it "should be the value of the authority attribute on the roleTerm element" do
581
- expect(@mods_w_code.plain_name.role.authority).to eq(["marcrelator"])
582
- expect(@mods_w_text.plain_name.role.authority).to eq(["marcrelator"])
583
- expect(@mods_w_both.plain_name.role.authority).to eq(["marcrelator"])
584
- end
585
- end
586
- context "code" do
587
- it "should be empty if the roleTerm is not of type code" do
588
- expect(@mods_w_text.plain_name.role.code.size).to eq(0)
589
- expect(@mods_wo_authority.plain_name.role.code.size).to eq(0)
590
- end
591
- it "should be the value of the roleTerm element if element's type attribute is 'code'" do
592
- expect(@mods_w_code.plain_name.role.code).to eq(["drt"])
593
- expect(@mods_w_both.plain_name.role.code).to eq(["cre"])
594
- end
595
- end
596
- context "pertaining to a specific name" do
597
- before(:all) do
598
- complex = "<mods #{@ns_decl}>
599
- <name>
600
- <namePart>Sean Connery</namePart>
601
- <role><roleTerm type='code' authority='marcrelator'>drt</roleTerm></role>
602
- </name>
603
- <name>
604
- <namePart>Pierce Brosnan</namePart>
605
- <role>
606
- <roleTerm type='text'>CreatorFake</roleTerm>
607
- <roleTerm type='code' authority='marcrelator'>cre</roleTerm>
608
- </role>
609
- <role><roleTerm type='text' authority='marcrelator'>Actor</roleTerm></role>
610
- </name>
611
- <name>
612
- <namePart>Daniel Craig</namePart>
613
- <role>
614
- <roleTerm type='text' authority='marcrelator'>Actor</roleTerm>
615
- <roleTerm type='code' authority='marcrelator'>cre</roleTerm>
616
- </role>
617
- </name>
618
- </mods>"
619
- @mods_complex = Mods::Record.new.from_str(complex)
620
- end
621
- it "roles should be empty array when there is no role element" do
622
- @mods_rec.from_str(@mods_w_pers_name_ns)
623
- expect(@mods_rec.personal_name.first.role.size).to eq(0)
624
- end
625
- it "object should have same number of roles as it has role nodes in xml" do
626
- expect(@mods_complex.plain_name[0].role.size).to eq(1)
627
- expect(@mods_complex.plain_name[1].role.size).to eq(2)
628
- expect(@mods_complex.plain_name[2].role.size).to eq(1)
629
- end
630
- context "name's roles should be correctly populated" do
631
- it "text attribute" do
632
- expect(@mods_complex.plain_name[0].role.value).to eq(['Director'])
633
- expect(@mods_complex.plain_name[1].role.value).to eq(['CreatorFake', 'Actor'])
634
- expect(@mods_complex.plain_name[2].role.value).to eq(['Actor'])
635
- end
636
- it "code attribute" do
637
- expect(@mods_complex.plain_name[0].role.code).to eq(['drt'])
638
- expect(@mods_complex.plain_name[1].role.code).to eq(['cre'])
639
- expect(@mods_complex.plain_name[2].role.code).to eq(['cre'])
640
- end
641
- it "authority attribute" do
642
- expect(@mods_complex.plain_name[0].role.authority).to eq(['marcrelator'])
643
- expect(@mods_complex.plain_name[1].role.authority).to eq(['marcrelator', 'marcrelator'])
644
- expect(@mods_complex.plain_name[2].role.authority).to eq(['marcrelator'])
645
- end
646
- it "multiple roles" do
647
- expect(@mods_mult_roles.plain_name.first.role.value).to eq(['Creator', 'Performer'])
648
- expect(@mods_mult_roles.plain_name.first.role.code).to eq(['cre'])
649
- expect(@mods_mult_roles.plain_name.role.first.roleTerm.authority.first).to eq('marcrelator')
650
- expect(@mods_mult_roles.plain_name.role.last.roleTerm.authority.size).to eq(0)
651
- end
652
- end
653
- end # pertaining to a specific name
654
- end # roles WITH namespaces
655
-
656
- context "convenience methods WITHOUT namespaces" do
657
- before(:all) do
658
- @mods_w_code = Mods::Record.new.from_str(@xml_w_code.sub(" #{@ns_decl}", ''), false)
659
- @mods_w_text = Mods::Record.new.from_str(@xml_w_text.sub(" #{@ns_decl}", ''), false)
660
- @mods_wo_authority = Mods::Record.new.from_str(@xml_wo_authority.sub(" #{@ns_decl}", ''), false)
661
- @mods_w_both = Mods::Record.new.from_str(@xml_w_both.sub(" #{@ns_decl}", ''), false)
662
- @mods_mult_roles = Mods::Record.new.from_str(@xml_w_mult_roles.sub(" #{@ns_decl}", ''), false)
663
- end
664
- context "value" do
665
- it "should be the value of a text roleTerm" do
666
- expect(@mods_w_text.plain_name.role.value).to eq(["Actor"])
667
- end
668
- it "should be the translation of the code if it is a marcrelator code and there is no text roleTerm" do
669
- expect(@mods_w_code.plain_name.role.value).to eq(["Director"])
670
- end
671
- it "should be the value of the text roleTerm if there are both a code and a text roleTerm" do
672
- expect(@mods_w_both.plain_name.role.value).to eq(["CreatorFake"])
673
- end
674
- it "should have 2 values if there are 2 role elements" do
675
- expect(@mods_mult_roles.plain_name.role.value).to eq(['Creator', 'Performer'])
676
- end
677
- end
678
- context "authority" do
679
- it "should be empty if it is missing from xml" do
680
- expect(@mods_wo_authority.plain_name.role.authority.size).to eq(0)
681
- end
682
- it "should be the value of the authority attribute on the roleTerm element" do
683
- expect(@mods_w_code.plain_name.role.authority).to eq(["marcrelator"])
684
- expect(@mods_w_text.plain_name.role.authority).to eq(["marcrelator"])
685
- expect(@mods_w_both.plain_name.role.authority).to eq(["marcrelator"])
686
- end
687
- end
688
- context "code" do
689
- it "should be empty if the roleTerm is not of type code" do
690
- expect(@mods_w_text.plain_name.role.code.size).to eq(0)
691
- expect(@mods_wo_authority.plain_name.role.code.size).to eq(0)
692
- end
693
- it "should be the value of the roleTerm element if element's type attribute is 'code'" do
694
- expect(@mods_w_code.plain_name.role.code).to eq(["drt"])
695
- expect(@mods_w_both.plain_name.role.code).to eq(["cre"])
696
- end
697
- end
698
- context "pertaining to a specific name" do
699
- before(:all) do
700
- complex = "<mods>
701
- <name>
702
- <namePart>Sean Connery</namePart>
703
- <role><roleTerm type='code' authority='marcrelator'>drt</roleTerm></role>
704
- </name>
705
- <name>
706
- <namePart>Pierce Brosnan</namePart>
707
- <role>
708
- <roleTerm type='text'>CreatorFake</roleTerm>
709
- <roleTerm type='code' authority='marcrelator'>cre</roleTerm>
710
- </role>
711
- <role><roleTerm type='text' authority='marcrelator'>Actor</roleTerm></role>
712
- </name>
713
- <name>
714
- <namePart>Daniel Craig</namePart>
715
- <role>
716
- <roleTerm type='text' authority='marcrelator'>Actor</roleTerm>
717
- <roleTerm type='code' authority='marcrelator'>cre</roleTerm>
718
- </role>
719
- </name>
720
- </mods>"
721
- @mods_complex = Mods::Record.new.from_str(complex, false)
722
- end
723
- it "roles should be empty array when there is no role element" do
724
- @mods_rec.from_str(@mods_w_pers_name_ns)
725
- expect(@mods_rec.personal_name.first.role.size).to eq(0)
726
- end
727
- it "object should have same number of roles as it has role nodes in xml" do
728
- expect(@mods_complex.plain_name[0].role.size).to eq(1)
729
- expect(@mods_complex.plain_name[1].role.size).to eq(2)
730
- expect(@mods_complex.plain_name[2].role.size).to eq(1)
731
- end
732
- context "name's roles should be correctly populated" do
733
- it "text attribute" do
734
- expect(@mods_complex.plain_name[0].role.value).to eq(['Director'])
735
- expect(@mods_complex.plain_name[1].role.value).to eq(['CreatorFake', 'Actor'])
736
- expect(@mods_complex.plain_name[2].role.value).to eq(['Actor'])
737
- end
738
- it "code attribute" do
739
- expect(@mods_complex.plain_name[0].role.code).to eq(['drt'])
740
- expect(@mods_complex.plain_name[1].role.code).to eq(['cre'])
741
- expect(@mods_complex.plain_name[2].role.code).to eq(['cre'])
742
- end
743
- it "authority attribute" do
744
- expect(@mods_complex.plain_name[0].role.authority).to eq(['marcrelator'])
745
- expect(@mods_complex.plain_name[1].role.authority).to eq(['marcrelator', 'marcrelator'])
746
- expect(@mods_complex.plain_name[2].role.authority).to eq(['marcrelator'])
747
- end
748
- it "multiple roles" do
749
- expect(@mods_mult_roles.plain_name.first.role.value).to eq(['Creator', 'Performer'])
750
- expect(@mods_mult_roles.plain_name.first.role.code).to eq(['cre'])
751
- expect(@mods_mult_roles.plain_name.role.first.roleTerm.authority.first).to eq('marcrelator')
752
- expect(@mods_mult_roles.plain_name.role.last.roleTerm.authority.size).to eq(0)
753
- end
754
- end
755
- end # pertaining to a specific name
756
- end # WITHOUT namespaces
757
- end # roles
758
-
759
- end