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/record_spec.rb DELETED
@@ -1,356 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "Mods::Record" do
4
- before(:all) do
5
- @ns_hash = {'mods' => Mods::MODS_NS}
6
- @def_ns_decl = "xmlns='#{Mods::MODS_NS}'"
7
- @example_ns_str = "<mods #{@def_ns_decl}><note>default ns</note></mods>"
8
- @example_no_ns_str = '<mods><note>no ns</note></mods>'
9
- @example_record_url = 'http://www.loc.gov/standards/mods/modsrdf/examples/0001.xml'
10
- @doc_from_str_ns = Mods::Reader.new.from_str(@example_ns_str)
11
- @doc_from_str_no_ns = Mods::Reader.new.from_str(@example_no_ns_str)
12
- end
13
-
14
- context "from_str" do
15
- before(:all) do
16
- @mods_ng_doc_w_ns = Mods::Record.new.from_str(@example_ns_str)
17
- end
18
- it "should return a mods record" do
19
- expect(@mods_ng_doc_w_ns).to be_a_kind_of(Mods::Record)
20
- end
21
- it "should have namespace aware parsing turned on by default" do
22
- expect(@mods_ng_doc_w_ns.namespaces.size).to be > 0
23
- end
24
- it "terminology should work with Record object defaults when mods string has namespaces" do
25
- expect(@mods_ng_doc_w_ns.note.map { |e| e.text }).to eq(['default ns'])
26
- end
27
- it "terminology should not work with Record object defaults when mods string has NO namespaces" do
28
- mods_ng_doc = Mods::Record.new.from_str(@example_no_ns_str)
29
- expect(mods_ng_doc.note.size).to eq(0)
30
- end
31
- it "should be allowed not to care about namespaces" do
32
- mods_ng_doc = Mods::Record.new.from_str(@example_no_ns_str, false)
33
- expect(mods_ng_doc.note.map { |e| e.text }).to eq(['no ns'])
34
- end
35
- end
36
-
37
- # Be able to create a new Mods::Record from a url
38
- context "from_url" do
39
- before(:all) do
40
- @mods_doc = Mods::Record.new.from_url(@example_record_url)
41
- end
42
- it "should return a mods record" do
43
- expect(@mods_doc).to be_a_kind_of(Mods::Record)
44
- end
45
- it "should raise an error on a bad url" do
46
- expect{Mods::Record.new.from_url("http://example.org/fake.xml")}.to raise_error
47
- end
48
- end
49
-
50
- # Be able to create a new Mods::Record from a file
51
- context "from_file" do
52
- before(:all) do
53
- @fixture_dir = File.join(File.dirname(__FILE__), 'fixture_data')
54
- @mods_doc = Mods::Record.new.from_file(File.join(@fixture_dir, 'shpc1.mods.xml'))
55
- end
56
- it "should return a mods record" do
57
- expect(@mods_doc).to be_a_kind_of(Mods::Record)
58
- end
59
- end
60
-
61
- context "from_nk_node" do
62
- before(:all) do
63
- oai_resp = '<?xml version="1.0" encoding="UTF-8"?>
64
- <OAI-PMH xmlns="http://www.openarchives.org/OAI/2.0/">
65
- <responseDate>2012-11-13T22:11:35Z</responseDate>
66
- <request>http://sul-lyberservices-prod.stanford.edu/sw-oai-provider/oai</request>
67
- <GetRecord>
68
- <record>
69
- <header>
70
- <identifier>oai:searchworks.stanford.edu/druid:mm848sz7984</identifier>
71
- <datestamp>2012-10-28T01:06:31Z</datestamp>
72
- </header>
73
- <metadata>
74
- <ns3:mods xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns3="http://www.loc.gov/mods/v3" xsi:schemaLocation="http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-2.xsd">
75
- <ns3:titleInfo>
76
- <ns3:title>boo</ns3:title>
77
- </ns3:titleInfo>
78
- </ns3:mods>
79
- </metadata>
80
- </record>
81
- </GetRecord>
82
- </OAI-PMH>'
83
- ng_xml = Nokogiri::XML(oai_resp)
84
- @mods_node = ng_xml.xpath('//mods:mods', @ns_hash).first
85
- @mods_ng_doc = Mods::Record.new.from_nk_node(@mods_node)
86
- bad_ns_wrapped = '<?xml version="1.0" encoding="UTF-8"?>
87
- <metadata>
88
- <n:mods xmlns:n="http://www.not.mods.org">
89
- <n:titleInfo>
90
- <n:title>What? No namespaces?</n:title>
91
- </n:titleInfo>
92
- </n:mods>
93
- </metadata>'
94
- ng_xml = Nokogiri::XML(bad_ns_wrapped)
95
- @mods_node_no_ns = ng_xml.xpath('//n:mods', {'n'=>'http://www.not.mods.org'}).first
96
- end
97
- it "should return a mods record" do
98
- expect(@mods_ng_doc).to be_a_kind_of(Mods::Record)
99
- end
100
- it "should have namespace aware parsing turned on by default" do
101
- expect(@mods_ng_doc.namespaces.size).to be > 0
102
- end
103
- it "terminology should work with Record object defaults when mods string has namespaces" do
104
- expect(@mods_ng_doc.title_info.title.map { |e| e.text }).to eq(["boo"])
105
- end
106
- it "terminology should not work with Record object defaults when mods node has NO namespaces" do
107
- mods_ng_doc = Mods::Record.new.from_nk_node(@mods_node_no_ns)
108
- expect(mods_ng_doc.title_info.title.size).to eq(0)
109
- end
110
- it "should be allowed not to care about namespaces" do
111
- mods_ng_doc = Mods::Record.new.from_nk_node(@mods_node_no_ns, false)
112
- expect(mods_ng_doc.title_info.title.map { |e| e.text }).to eq(["What? No namespaces?"])
113
- end
114
- end # context from_nk_node
115
-
116
- context "getting term values" do
117
- before(:all) do
118
- m = "<mods #{@def_ns_decl}>
119
- <abstract>single</abstract>
120
- <genre></genre>
121
- <note>mult1</note>
122
- <note>mult2</note>
123
- <subject><topic>topic1</topic><topic>topic2</topic></subject>
124
- <subject><topic>topic3</topic></subject>
125
- </mods>"
126
- @mods_rec = Mods::Record.new
127
- @mods_rec.from_str(m)
128
- end
129
-
130
- context "term_value (single value result)" do
131
- it "should return nil if there are no such values in the MODS" do
132
- expect(@mods_rec.term_value(:identifier)).to be_nil
133
- end
134
- it "should return nil if there are only empty values in the MODS" do
135
- expect(@mods_rec.term_value(:genre)).to be_nil
136
- end
137
- it "should return a String for a single value" do
138
- expect(@mods_rec.term_value(:abstract)).to eq('single')
139
- end
140
- it "should return a String containing all values, with separator, for multiple values" do
141
- expect(@mods_rec.term_value(:note)).to eq('mult1 mult2')
142
- end
143
- it "should work with an Array of messages passed as the argument" do
144
- expect(@mods_rec.term_value([:subject, 'topic'])).to eq('topic1 topic2 topic3')
145
- end
146
- it "should take a separator argument" do
147
- expect(@mods_rec.term_value(:note, ' -|-')).to eq('mult1 -|-mult2')
148
- end
149
- end
150
-
151
- context "term_values (multiple values)" do
152
- it "should return nil if there are no such values in the MODS" do
153
- expect(@mods_rec.term_values(:identifier)).to be_nil
154
- end
155
- it "should return nil if there are only empty values in the MODS" do
156
- expect(@mods_rec.term_values(:genre)).to be_nil
157
- end
158
- it "should return an array of size one for a single value" do
159
- expect(@mods_rec.term_values(:abstract)).to eq(['single'])
160
- end
161
- it "should return an array of values for multiple values" do
162
- expect(@mods_rec.term_values(:note)).to eq(['mult1', 'mult2'])
163
- end
164
- it "should work with an Array of messages passed as the argument" do
165
- expect(@mods_rec.term_values([:subject, 'topic'])).to eq(['topic1', 'topic2', 'topic3'])
166
- end
167
- it "should work with a String passed as the argument" do
168
- expect(@mods_rec.term_values('abstract')).to eq(['single'])
169
- end
170
- it "should raise an error for an unrecognized message symbol" do
171
- expect { @mods_rec.term_values(:not_there) }.to raise_error(ArgumentError, "term_values called with unknown argument: :not_there")
172
- end
173
- it "should raise an error if the argument is an Array containing non-symbols" do
174
- expect { @mods_rec.term_values([:subject, @mods_rec.subject]) }.to raise_error(ArgumentError, /term_values called with Array containing unrecognized class:.*NodeSet.*/)
175
- end
176
- it "should raise an error if the argument isn't a Symbol or an Array" do
177
- expect { @mods_rec.term_values(@mods_rec.subject) }.to raise_error(ArgumentError, /term_values called with unrecognized argument class:.*NodeSet.*/)
178
- end
179
- end
180
- end # getting term values
181
-
182
- context "convenience methods for accessing tricky bits of terminology" do
183
- before(:all) do
184
- @mods_rec = Mods::Record.new
185
- end
186
- context "title methods" do
187
- it "short_titles should return an Array of Strings (multiple titles are legal in Mods)" do
188
- @mods_rec.from_str("<mods #{@def_ns_decl}><titleInfo><title>Jerk</title><nonSort>The</nonSort></titleInfo><titleInfo><title>Joke</title></titleInfo></mods>")
189
- expect(@mods_rec.short_titles).to eq(["The Jerk", "Joke"])
190
- end
191
- it "full_titles should return an Array of Strings (multiple titles are legal in Mods)" do
192
- @mods_rec.from_str("<mods #{@def_ns_decl}><titleInfo><title>Jerk</title><nonSort>The</nonSort></titleInfo><titleInfo><title>Joke</title></titleInfo></mods>")
193
- expect(@mods_rec.full_titles).to eq(["The Jerk", "Joke"])
194
- end
195
- it "sort_title should return a String (sortable fields are single valued)" do
196
- @mods_rec.from_str("<mods #{@def_ns_decl}><titleInfo><title>Jerk</title><subTitle>A Tale of Tourettes</subTitle><nonSort>The</nonSort></titleInfo></mods>")
197
- expect(@mods_rec.sort_title).to eq("Jerk A Tale of Tourettes")
198
- end
199
- it "alternative_titles should return an Array of Strings (multiple alternative titles when there are multiple titleInfo elements)" do
200
- @mods_rec.from_str("<mods #{@def_ns_decl}><titleInfo type='alternative'><title>1</title></titleInfo><titleInfo type='alternative'><title>2</title></titleInfo></mods>")
201
- expect(@mods_rec.alternative_titles).to eq(['1', '2'])
202
- @mods_rec.from_str("<mods #{@def_ns_decl}><titleInfo type='alternative'><title>1</title><title>2</title></titleInfo></mods>")
203
- expect(@mods_rec.alternative_titles).to eq(['12'])
204
- end
205
- end
206
-
207
- context "personal_names" do
208
- before(:all) do
209
- @pers_name = 'Crusty'
210
- @mods_w_pers_name = "<mods #{@def_ns_decl}><name type='personal'><namePart>#{@pers_name}</namePart></name></mods>"
211
- @pers_role = 'creator'
212
- @mods_w_pers_name_role = "<mods #{@def_ns_decl}><name type='personal'><namePart>#{@pers_name}</namePart>"
213
- @given_family = '<mods xmlns="http://www.loc.gov/mods/v3"><name type="personal"><namePart type="given">Jorge Luis</namePart>
214
- <namePart type="family">Borges</namePart></name></mods>'
215
- @given_family_date = '<mods xmlns="http://www.loc.gov/mods/v3"><name type="personal"><namePart type="given">Zaphod</namePart>
216
- <namePart type="family">Beeblebrox</namePart>
217
- <namePart type="date">1912-2362</namePart></name></mods>'
218
- @all_name_parts = '<mods xmlns="http://www.loc.gov/mods/v3"><name type="personal"><namePart type="given">Given</namePart>
219
- <namePart type="family">Family</namePart>
220
- <namePart type="termsOfAddress">Mr.</namePart>
221
- <namePart type="date">date</namePart></name></mods>'
222
- @family_only = '<mods xmlns="http://www.loc.gov/mods/v3"><name type="personal"><namePart type="family">Family</namePart></name></mods>'
223
- @given_only = '<mods xmlns="http://www.loc.gov/mods/v3"><name type="personal"><namePart type="given">Given</namePart></name></mods>'
224
- end
225
-
226
- it "should return an Array of Strings" do
227
- @mods_rec.from_str(@mods_w_pers_name)
228
- expect(@mods_rec.personal_names).to eq([@pers_name])
229
- end
230
-
231
- it "should not include the role text" do
232
- @mods_rec.from_str(@mods_w_pers_name_role)
233
- expect(@mods_rec.personal_names.first).not_to match(@pers_role)
234
- end
235
-
236
- it "should prefer displayForm over namePart pieces" do
237
- display_form_and_name_parts = '<mods xmlns="http://www.loc.gov/mods/v3"><name type="personal"><namePart type="given">Jorge Luis</namePart>
238
- <namePart type="family">Borges</namePart>
239
- <displayForm>display form</displayForm></name></mods>'
240
- @mods_rec.from_str(display_form_and_name_parts)
241
- expect(@mods_rec.personal_names).to include("display form")
242
- end
243
-
244
- it "should put the family namePart first" do
245
- @mods_rec.from_str(@given_family)
246
- expect(@mods_rec.personal_names.first).to match(/^Borges/)
247
- @mods_rec.from_str(@given_family_date)
248
- expect(@mods_rec.personal_names.first).to match(/^Beeblebrox/)
249
- end
250
- it "should not include date" do
251
- @mods_rec.from_str(@given_family_date)
252
- expect(@mods_rec.personal_names.first).not_to match(/19/)
253
- @mods_rec.from_str(@all_name_parts)
254
- expect(@mods_rec.personal_names.first).not_to match('date')
255
- end
256
- it "should include a comma when there is both a family and a given name" do
257
- @mods_rec.from_str(@all_name_parts)
258
- expect(@mods_rec.personal_names).to include("Family, Given Mr.")
259
- end
260
- it "should include multiple words in a namePart" do
261
- @mods_rec.from_str(@given_family)
262
- expect(@mods_rec.personal_names).to include("Borges, Jorge Luis")
263
- end
264
- it "should not include a comma when there is only a family or given name" do
265
- [@family_only, @given_only].each { |mods_str|
266
- @mods_rec.from_str(mods_str)
267
- expect(@mods_rec.personal_names.first).not_to match(/,/)
268
- }
269
- end
270
- it "should include terms of address" do
271
- @mods_rec.from_str(@all_name_parts)
272
- expect(@mods_rec.personal_names.first).to match(/Mr./)
273
- end
274
- end # personal_names
275
-
276
- context "personal_names_w_dates" do
277
- before(:all) do
278
- @given_family = '<mods xmlns="http://www.loc.gov/mods/v3"><name type="personal"><namePart type="given">Jorge Luis</namePart>
279
- <namePart type="family">Borges</namePart></name></mods>'
280
- @given_family_date = '<mods xmlns="http://www.loc.gov/mods/v3"><name type="personal"><namePart type="given">Zaphod</namePart>
281
- <namePart type="family">Beeblebrox</namePart>
282
- <namePart type="date">1912-2362</namePart></name></mods>'
283
- @all_name_parts = '<mods xmlns="http://www.loc.gov/mods/v3"><name type="personal"><namePart type="given">Given</namePart>
284
- <namePart type="family">Family</namePart>
285
- <namePart type="termsOfAddress">Mr.</namePart>
286
- <namePart type="date">date</namePart></name></mods>'
287
- end
288
- it "should return an Array of Strings" do
289
- @mods_rec.from_str(@given_family_date)
290
- expect(@mods_rec.personal_names_w_dates).to be_an_instance_of(Array)
291
- end
292
- it "should include the date when it is available" do
293
- @mods_rec.from_str(@given_family_date)
294
- expect(@mods_rec.personal_names_w_dates.first).to match(/, 1912-2362$/)
295
- @mods_rec.from_str(@all_name_parts)
296
- expect(@mods_rec.personal_names_w_dates.first).to match(/, date$/)
297
- end
298
- it "should be just the personal_name if no date is available" do
299
- @mods_rec.from_str(@given_family)
300
- expect(@mods_rec.personal_names_w_dates.first).to eq('Borges, Jorge Luis')
301
- end
302
- end
303
-
304
- context "corporate_names" do
305
- before(:all) do
306
- @corp_name = 'ABC corp'
307
- end
308
- it "should return an Array of Strings" do
309
- @mods_rec.from_str("<mods #{@def_ns_decl}><name type='corporate'><namePart>#{@corp_name}</namePart></name></mods>")
310
- expect(@mods_rec.corporate_names).to eq([@corp_name])
311
- end
312
- it "should not include the role text" do
313
- corp_role = 'lithographer'
314
- mods_w_corp_name_role = "<mods #{@def_ns_decl}><name type='corporate'><namePart>#{@corp_name}</namePart>
315
- <role><roleTerm type='text'>#{corp_role}</roleTerm></role></name></mods>"
316
- @mods_rec.from_str(mods_w_corp_name_role)
317
- expect(@mods_rec.corporate_names.first).not_to match(corp_role)
318
- end
319
-
320
- it "should prefer displayForm over namePart pieces" do
321
- display_form_and_name_parts = "<mods #{@def_ns_decl}><name type='corporate'><namePart>Food, Inc.</namePart>
322
- <displayForm>display form</displayForm></name></mods>"
323
- @mods_rec.from_str(display_form_and_name_parts)
324
- expect(@mods_rec.corporate_names).to include("display form")
325
- end
326
- end # corporate_names
327
-
328
- context "languages" do
329
- before(:all) do
330
- @simple = "<mods #{@def_ns_decl}><language>Greek</language></mods>"
331
- @iso639_2b_code = "<mods #{@def_ns_decl}><language><languageTerm authority='iso639-2b' type='code'>fre</languageTerm></language></mods>"
332
- @iso639_2b_text = "<mods #{@def_ns_decl}><language><languageTerm authority='iso639-2b' type='text'>English</languageTerm></language></mods>"
333
- @mult_codes = "<mods #{@def_ns_decl}><language><languageTerm authority='iso639-2b' type='code'>per ara, dut</languageTerm></language></mods>"
334
- end
335
- it "should translate iso639-2b codes to English" do
336
- @mods_rec.from_str(@iso639_2b_code)
337
- expect(@mods_rec.languages).to eq(["French"])
338
- end
339
- it "should pass thru language values that are already text (not code)" do
340
- @mods_rec.from_str(@iso639_2b_text)
341
- expect(@mods_rec.languages).to eq(["English"])
342
- end
343
- it "should keep values that are not inside <languageTerm> elements" do
344
- @mods_rec.from_str(@simple)
345
- expect(@mods_rec.languages).to eq(["Greek"])
346
- end
347
- it "should create a separate value for each language in a comma, space, or | separated list " do
348
- @mods_rec.from_str(@mult_codes)
349
- expect(@mods_rec.languages).to include("Arabic")
350
- expect(@mods_rec.languages).to include("Persian")
351
- expect(@mods_rec.languages).to include("Dutch; Flemish")
352
- end
353
- end
354
- end # convenience methods for tricky bits of terminology
355
-
356
- end
@@ -1,305 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "Mods <relatedItem> Element" do
4
- before(:all) do
5
- @mods_rec = Mods::Record.new
6
- @ns_decl = "xmlns='#{Mods::MODS_NS}'"
7
- end
8
-
9
- it "should associate the right pieces with the right <relatedItem> elements" do
10
- skip "to be implemented (Mods::RelatedItem object)"
11
- end
12
-
13
- context "basic <related_item> terminology pieces" do
14
-
15
- context "WITH namespaces" do
16
- before(:all) do
17
- @rel_it1 = @mods_rec.from_str("<mods #{@ns_decl}><relatedItem displayLabel='Bibliography' type='host'>
18
- <titleInfo>
19
- <title/>
20
- </titleInfo>
21
- <recordInfo>
22
- <recordIdentifier source='Gallica ARK'/>
23
- </recordInfo>
24
- <typeOfResource>text</typeOfResource>
25
- </relatedItem></mods>").related_item
26
- @rel_it_mult = @mods_rec.from_str("<mods #{@ns_decl}><relatedItem>
27
- <titleInfo>
28
- <title>Complete atlas, or, Distinct view of the known world</title>
29
- </titleInfo>
30
- <name type='personal'>
31
- <namePart>Bowen, Emanuel,</namePart>
32
- <namePart type='date'>d. 1767</namePart>
33
- </name>
34
- </relatedItem>
35
- <relatedItem type='host' displayLabel='From:'>
36
- <titleInfo>
37
- <title>Complete atlas, or, Distinct view of the known world</title>
38
- </titleInfo>
39
- <name>
40
- <namePart>Bowen, Emanuel, d. 1767.</namePart>
41
- </name>
42
- <identifier type='local'>(AuCNL)1669726</identifier>
43
- </relatedItem></mods>").related_item
44
- @rel_it2 = @mods_rec.from_str("<mods #{@ns_decl}><relatedItem type='constituent' ID='MODSMD_ARTICLE1'>
45
- <titleInfo>
46
- <title>Nuppineula.</title>
47
- </titleInfo>
48
- <genre>article</genre>
49
- <part ID='DIVL15' type='paragraph' order='1'/>
50
- <part ID='DIVL17' type='paragraph' order='2'/>
51
- <part ID='DIVL19' type='paragraph' order='3'/>
52
- </relatedItem></mods>").related_item
53
- @coll_ex = @mods_rec.from_str("<mods #{@ns_decl}><relatedItem type='host'>
54
- <titleInfo>
55
- <title>The Collier Collection of the Revs Institute for Automotive Research</title>
56
- </titleInfo>
57
- <typeOfResource collection='yes'/>
58
- </relatedItem></mods>").related_item
59
- end
60
-
61
- it ".relatedItem should be a NodeSet" do
62
- [@rel_it1, @rel_it_mult, @rel_it2, @coll_ex].each { |ri| expect(ri).to be_an_instance_of(Nokogiri::XML::NodeSet) }
63
- end
64
- it ".relatedItem should have as many members as there are <recordInfo> elements in the xml" do
65
- [@rel_it1, @rel_it2, @coll_ex].each { |ri| expect(ri.size).to eq(1) }
66
- expect(@rel_it_mult.size).to eq(2)
67
- end
68
- it "relatedItem.type_at should match type attribute" do
69
- [@rel_it1, @rel_it_mult, @coll_ex].each { |ri| expect(ri.type_at).to eq(['host']) }
70
- expect(@rel_it2.type_at).to eq(['constituent'])
71
- end
72
- it "relatedItem.id_at should match ID attribute" do
73
- expect(@rel_it2.id_at).to eq(['MODSMD_ARTICLE1'])
74
- [@rel_it1, @rel_it_mult, @coll_ex].each { |ri| expect(ri.id_at.size).to eq(0) }
75
- end
76
- it "relatedItem.displayLabel should match displayLabel attribute" do
77
- expect(@rel_it1.displayLabel).to eq(['Bibliography'])
78
- expect(@rel_it_mult.displayLabel).to eq(['From:'])
79
- [@rel_it2, @coll_ex].each { |ri| expect(ri.displayLabel.size).to eq(0) }
80
- end
81
-
82
- context "<genre> child element" do
83
- it "relatedItem.genre should match <relatedItem><genre>" do
84
- expect(@rel_it2.genre.map { |ri| ri.text }).to eq(['article'])
85
- end
86
- end # <genre> child element
87
-
88
- context "<identifier> child element" do
89
- it "relatedItem.identifier.type_at should match <relatedItem><identifier type=''> attribute" do
90
- expect(@rel_it_mult.identifier.type_at).to eq(['local'])
91
- end
92
- it "relatedItem.identifier should match <relatedItem><identifier>" do
93
- expect(@rel_it_mult.identifier.map { |n| n.text }).to eq(['(AuCNL)1669726'])
94
- end
95
- end # <identifier> child element
96
-
97
- context "<name> child element" do
98
- it "relatedItem.personal_name.namePart should match <relatedItem><name type='personal'><namePart>" do
99
- expect(@rel_it_mult.personal_name.namePart.map { |n| n.text }.size).to eq(2)
100
- expect(@rel_it_mult.personal_name.namePart.map { |n| n.text }).to include('Bowen, Emanuel,')
101
- expect(@rel_it_mult.personal_name.namePart.map { |n| n.text }).to include('d. 1767')
102
- expect(@rel_it_mult.personal_name.namePart.map { |n| n.text }).not_to include('Bowen, Emanuel, d. 1767.')
103
- end
104
- it "relatedItem.personal_name.date should match <relatedItem><name type='personal'><namePart type='date'>" do
105
- expect(@rel_it_mult.personal_name.date.map { |n| n.text }).to eq(['d. 1767'])
106
- end
107
- it "relatedItem.name_el.namePart should match <relatedItem><name><namePart>" do
108
- expect(@rel_it_mult.name_el.namePart.map { |n| n.text }.size).to eq(3)
109
- expect(@rel_it_mult.name_el.namePart.map { |n| n.text }).to include('Bowen, Emanuel,')
110
- expect(@rel_it_mult.name_el.namePart.map { |n| n.text }).to include('d. 1767')
111
- expect(@rel_it_mult.name_el.namePart.map { |n| n.text }).to include('Bowen, Emanuel, d. 1767.')
112
- end
113
- end # <name> child element
114
-
115
- context "<part> child element" do
116
- it "relatedItem.part.type_at should match <relatedItem><part type=''> attribute" do
117
- expect(@rel_it2.part.type_at).to eq(['paragraph', 'paragraph', 'paragraph'])
118
- end
119
- it "relatedItem.part.id_at should match <relatedItem><part ID=''> attribute" do
120
- expect(@rel_it2.part.id_at.size).to eq(3)
121
- expect(@rel_it2.part.id_at).to include('DIVL15')
122
- expect(@rel_it2.part.id_at).to include('DIVL17')
123
- expect(@rel_it2.part.id_at).to include('DIVL19')
124
- end
125
- it "relatedItem.part.order should match <relatedItem><part order=''> attribute" do
126
- expect(@rel_it2.part.order.size).to eq(3)
127
- expect(@rel_it2.part.order).to include('1')
128
- expect(@rel_it2.part.order).to include('2')
129
- expect(@rel_it2.part.order).to include('3')
130
- end
131
- end # <part> child element
132
-
133
- context "<recordInfo> child element" do
134
- it "relatedItem.recordInfo.recordIdentifier.source should match <relatedItem><recordInfo><recordIdentifier source> attribute" do
135
- expect(@rel_it1.recordInfo.recordIdentifier.source).to eq(['Gallica ARK'])
136
- end
137
- end # <recordInfo> child element
138
-
139
- context "<titleInfo> child element" do
140
- it "relatedItem.titleInfo.title should access <relatedItem><titleInfo><title>" do
141
- expect(@rel_it1.titleInfo.title.map { |n| n.text }).to eq([''])
142
- expect(@rel_it_mult.titleInfo.title.map { |n| n.text }).to eq(['Complete atlas, or, Distinct view of the known world', 'Complete atlas, or, Distinct view of the known world'])
143
- expect(@rel_it2.titleInfo.title.map { |n| n.text }).to eq(['Nuppineula.'])
144
- expect(@coll_ex.titleInfo.title.map { |n| n.text }).to eq(['The Collier Collection of the Revs Institute for Automotive Research'])
145
- end
146
- end # <titleInfo> child element
147
-
148
- context "<typeOfResource> child element" do
149
- it "relatedItem.typeOfResource should access <relatedItem><typeOfResource>" do
150
- expect(@rel_it1.typeOfResource.map { |n| n.text }).to eq(['text'])
151
- end
152
- it "relatedItem.typeOfResource.collection should access <relatedItem><typeOfResource collection='yes'> attribute" do
153
- expect(@coll_ex.typeOfResource.collection).to eq(['yes'])
154
- end
155
- end # <typeOfResource> child element
156
-
157
- end # WITH namespaces
158
-
159
- context "WITHOUT namespaces" do
160
- before(:all) do
161
- @rel_it1 = @mods_rec.from_str("<mods><relatedItem displayLabel='Bibliography' type='host'>
162
- <titleInfo>
163
- <title/>
164
- </titleInfo>
165
- <recordInfo>
166
- <recordIdentifier source='Gallica ARK'/>
167
- </recordInfo>
168
- <typeOfResource>text</typeOfResource>
169
- </relatedItem></mods>", false).related_item
170
- @rel_it_mult = @mods_rec.from_str("<mods><relatedItem>
171
- <titleInfo>
172
- <title>Complete atlas, or, Distinct view of the known world</title>
173
- </titleInfo>
174
- <name type='personal'>
175
- <namePart>Bowen, Emanuel,</namePart>
176
- <namePart type='date'>d. 1767</namePart>
177
- </name>
178
- </relatedItem>
179
- <relatedItem type='host' displayLabel='From:'>
180
- <titleInfo>
181
- <title>Complete atlas, or, Distinct view of the known world</title>
182
- </titleInfo>
183
- <name>
184
- <namePart>Bowen, Emanuel, d. 1767.</namePart>
185
- </name>
186
- <identifier type='local'>(AuCNL)1669726</identifier>
187
- </relatedItem></mods>", false).related_item
188
- @rel_it2 = @mods_rec.from_str("<mods><relatedItem type='constituent' ID='MODSMD_ARTICLE1'>
189
- <titleInfo>
190
- <title>Nuppineula.</title>
191
- </titleInfo>
192
- <genre>article</genre>
193
- <part ID='DIVL15' type='paragraph' order='1'/>
194
- <part ID='DIVL17' type='paragraph' order='2'/>
195
- <part ID='DIVL19' type='paragraph' order='3'/>
196
- </relatedItem></mods>", false).related_item
197
- @coll_ex = @mods_rec.from_str("<mods><relatedItem type='host'>
198
- <titleInfo>
199
- <title>The Collier Collection of the Revs Institute for Automotive Research</title>
200
- </titleInfo>
201
- <typeOfResource collection='yes'/>
202
- </relatedItem></mods>", false).related_item
203
- end
204
-
205
- it ".relatedItem should be a NodeSet" do
206
- [@rel_it1, @rel_it_mult, @rel_it2, @coll_ex].each { |ri| expect(ri).to be_an_instance_of(Nokogiri::XML::NodeSet) }
207
- end
208
- it ".relatedItem should have as many members as there are <recordInfo> elements in the xml" do
209
- [@rel_it1, @rel_it2, @coll_ex].each { |ri| expect(ri.size).to eq(1) }
210
- expect(@rel_it_mult.size).to eq(2)
211
- end
212
- it "relatedItem.type_at should match type attribute" do
213
- [@rel_it1, @rel_it_mult, @coll_ex].each { |ri| expect(ri.type_at).to eq(['host']) }
214
- expect(@rel_it2.type_at).to eq(['constituent'])
215
- end
216
- it "relatedItem.id_at should match ID attribute" do
217
- expect(@rel_it2.id_at).to eq(['MODSMD_ARTICLE1'])
218
- [@rel_it1, @rel_it_mult, @coll_ex].each { |ri| expect(ri.id_at.size).to eq(0) }
219
- end
220
- it "relatedItem.displayLabel should match displayLabel attribute" do
221
- expect(@rel_it1.displayLabel).to eq(['Bibliography'])
222
- expect(@rel_it_mult.displayLabel).to eq(['From:'])
223
- [@rel_it2, @coll_ex].each { |ri| expect(ri.displayLabel.size).to eq(0) }
224
- end
225
-
226
- context "<genre> child element" do
227
- it "relatedItem.genre should match <relatedItem><genre>" do
228
- expect(@rel_it2.genre.map { |ri| ri.text }).to eq(['article'])
229
- end
230
- end # <genre> child element
231
-
232
- context "<identifier> child element" do
233
- it "relatedItem.identifier.type_at should match <relatedItem><identifier type=''> attribute" do
234
- expect(@rel_it_mult.identifier.type_at).to eq(['local'])
235
- end
236
- it "relatedItem.identifier should match <relatedItem><identifier>" do
237
- expect(@rel_it_mult.identifier.map { |n| n.text }).to eq(['(AuCNL)1669726'])
238
- end
239
- end # <identifier> child element
240
-
241
- context "<name> child element" do
242
- it "relatedItem.personal_name.namePart should match <relatedItem><name type='personal'><namePart>" do
243
- expect(@rel_it_mult.personal_name.namePart.map { |n| n.text }.size).to eq(2)
244
- expect(@rel_it_mult.personal_name.namePart.map { |n| n.text }).to include('Bowen, Emanuel,')
245
- expect(@rel_it_mult.personal_name.namePart.map { |n| n.text }).to include('d. 1767')
246
- expect(@rel_it_mult.personal_name.namePart.map { |n| n.text }).not_to include('Bowen, Emanuel, d. 1767.')
247
- end
248
- it "relatedItem.personal_name.date should match <relatedItem><name type='personal'><namePart type='date'>" do
249
- expect(@rel_it_mult.personal_name.date.map { |n| n.text }).to eq(['d. 1767'])
250
- end
251
- it "relatedItem.name_el.namePart should match <relatedItem><name><namePart>" do
252
- expect(@rel_it_mult.name_el.namePart.map { |n| n.text }.size).to eq(3)
253
- expect(@rel_it_mult.name_el.namePart.map { |n| n.text }).to include('Bowen, Emanuel,')
254
- expect(@rel_it_mult.name_el.namePart.map { |n| n.text }).to include('d. 1767')
255
- expect(@rel_it_mult.name_el.namePart.map { |n| n.text }).to include('Bowen, Emanuel, d. 1767.')
256
- end
257
- end # <name> child element
258
-
259
- context "<part> child element" do
260
- it "relatedItem.part.type_at should match <relatedItem><part type=''> attribute" do
261
- expect(@rel_it2.part.type_at).to eq(['paragraph', 'paragraph', 'paragraph'])
262
- end
263
- it "relatedItem.part.id_at should match <relatedItem><part ID=''> attribute" do
264
- expect(@rel_it2.part.id_at.size).to eq(3)
265
- expect(@rel_it2.part.id_at).to include('DIVL15')
266
- expect(@rel_it2.part.id_at).to include('DIVL17')
267
- expect(@rel_it2.part.id_at).to include('DIVL19')
268
- end
269
- it "relatedItem.part.order should match <relatedItem><part order=''> attribute" do
270
- expect(@rel_it2.part.order.size).to eq(3)
271
- expect(@rel_it2.part.order).to include('1')
272
- expect(@rel_it2.part.order).to include('2')
273
- expect(@rel_it2.part.order).to include('3')
274
- end
275
- end # <part> child element
276
-
277
- context "<recordInfo> child element" do
278
- it "relatedItem.recordInfo.recordIdentifier.source should match <relatedItem><recordInfo><recordIdentifier source> attribute" do
279
- expect(@rel_it1.recordInfo.recordIdentifier.source).to eq(['Gallica ARK'])
280
- end
281
- end # <recordInfo> child element
282
-
283
- context "<titleInfo> child element" do
284
- it "relatedItem.titleInfo.title should access <relatedItem><titleInfo><title>" do
285
- expect(@rel_it1.titleInfo.title.map { |n| n.text }).to eq([''])
286
- expect(@rel_it_mult.titleInfo.title.map { |n| n.text }).to eq(['Complete atlas, or, Distinct view of the known world', 'Complete atlas, or, Distinct view of the known world'])
287
- expect(@rel_it2.titleInfo.title.map { |n| n.text }).to eq(['Nuppineula.'])
288
- expect(@coll_ex.titleInfo.title.map { |n| n.text }).to eq(['The Collier Collection of the Revs Institute for Automotive Research'])
289
- end
290
- end # <titleInfo> child element
291
-
292
- context "<typeOfResource> child element" do
293
- it "relatedItem.typeOfResource should access <relatedItem><typeOfResource>" do
294
- expect(@rel_it1.typeOfResource.map { |n| n.text }).to eq(['text'])
295
- end
296
- it "relatedItem.typeOfResource.collection should access <relatedItem><typeOfResource collection='yes'> attribute" do
297
- expect(@coll_ex.typeOfResource.collection).to eq(['yes'])
298
- end
299
- end # <typeOfResource> child element
300
-
301
- end # WITHOUT namespaces
302
-
303
- end # basic <related_item> terminology pieces
304
-
305
- end