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