mods 2.3.0 → 3.0.0.alpha1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/ruby.yml +24 -0
- data/.gitignore +1 -0
- data/Gemfile +1 -5
- data/README.md +1 -3
- data/lib/mods/marc_country_codes.rb +12 -10
- data/lib/mods/nom_terminology.rb +109 -848
- data/lib/mods/origin_info.rb +3 -1
- data/lib/mods/reader.rb +9 -39
- data/lib/mods/record.rb +13 -28
- data/lib/mods/version.rb +1 -1
- data/mods.gemspec +4 -4
- data/spec/fixture_data/hp566jq8781.xml +334 -0
- data/spec/integration/parker_spec.rb +217 -0
- data/spec/{date_spec.rb → lib/date_spec.rb} +0 -0
- data/spec/lib/language_spec.rb +123 -0
- data/spec/lib/location_spec.rb +175 -0
- data/spec/lib/name_spec.rb +366 -0
- data/spec/lib/origin_info_spec.rb +134 -0
- data/spec/lib/part_spec.rb +162 -0
- data/spec/lib/physical_description_spec.rb +72 -0
- data/spec/{reader_spec.rb → lib/reader_spec.rb} +1 -41
- data/spec/lib/record_info_spec.rb +114 -0
- data/spec/lib/record_spec.rb +287 -0
- data/spec/lib/related_item_spec.rb +124 -0
- data/spec/lib/subject_spec.rb +427 -0
- data/spec/lib/title_spec.rb +108 -0
- data/spec/lib/top_level_elmnts_simple_spec.rb +169 -0
- data/spec/spec_helper.rb +87 -6
- data/spec/support/fixtures.rb +9 -0
- metadata +65 -47
- data/.coveralls.yml +0 -1
- data/.travis.yml +0 -12
- data/spec/language_spec.rb +0 -118
- data/spec/location_spec.rb +0 -295
- data/spec/name_spec.rb +0 -759
- data/spec/origin_info_spec.rb +0 -442
- data/spec/part_spec.rb +0 -471
- data/spec/physical_description_spec.rb +0 -144
- data/spec/record_info_spec.rb +0 -493
- data/spec/record_spec.rb +0 -356
- data/spec/related_item_spec.rb +0 -305
- data/spec/subject_spec.rb +0 -809
- data/spec/title_spec.rb +0 -226
- data/spec/top_level_elmnts_simple_spec.rb +0 -369
data/spec/part_spec.rb
DELETED
@@ -1,471 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "Mods <part> 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 normalize dates" do
|
10
|
-
skip "to be implemented"
|
11
|
-
end
|
12
|
-
|
13
|
-
context "basic <part> terminology pieces" do
|
14
|
-
|
15
|
-
context "WITH namespaces" do
|
16
|
-
before(:all) do
|
17
|
-
@ex = @mods_rec.from_str("<mods #{@ns_decl}><part>
|
18
|
-
<detail>
|
19
|
-
<title>Wayfarers (Poem)</title>
|
20
|
-
</detail>
|
21
|
-
<extent unit='pages'>
|
22
|
-
<start>97</start>
|
23
|
-
<end>98</end>
|
24
|
-
</extent>
|
25
|
-
</part></mods>").part
|
26
|
-
@ex2 = @mods_rec.from_str("<mods #{@ns_decl}><part>
|
27
|
-
<detail type='page number'>
|
28
|
-
<number>3</number>
|
29
|
-
</detail>
|
30
|
-
<extent unit='pages'>
|
31
|
-
<start>3</start>
|
32
|
-
</extent>
|
33
|
-
</part></mods>").part
|
34
|
-
@detail = @mods_rec.from_str("<mods #{@ns_decl}><part>
|
35
|
-
<detail type='issue'>
|
36
|
-
<number>1</number>
|
37
|
-
<caption>no.</caption>
|
38
|
-
</detail>
|
39
|
-
</part></mods>").part
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should be a NodeSet" do
|
43
|
-
[@ex, @ex2, @detail].each { |p| expect(p).to be_an_instance_of(Nokogiri::XML::NodeSet) }
|
44
|
-
end
|
45
|
-
it "should have as many members as there are <part> elements in the xml" do
|
46
|
-
[@ex, @ex2, @detail].each { |p| expect(p.size).to eq(1) }
|
47
|
-
end
|
48
|
-
it "should recognize type(_at) attribute on <part> element" do
|
49
|
-
@mods_rec.from_str("<mods #{@ns_decl}><part type='val'>anything</part></mods>")
|
50
|
-
expect(@mods_rec.part.type_at).to eq(['val'])
|
51
|
-
end
|
52
|
-
it "should recognize order attribute on <part> element" do
|
53
|
-
@mods_rec.from_str("<mods #{@ns_decl}><part order='val'>anything</part></mods>")
|
54
|
-
expect(@mods_rec.part.order).to eq(['val'])
|
55
|
-
end
|
56
|
-
it "should recognize ID attribute on <part> element as id_at term" do
|
57
|
-
@mods_rec.from_str("<mods #{@ns_decl}><part ID='val'>anything</part></mods>")
|
58
|
-
expect(@mods_rec.part.id_at).to eq(['val'])
|
59
|
-
end
|
60
|
-
|
61
|
-
context "<detail> child element" do
|
62
|
-
it "should be a NodeSet" do
|
63
|
-
[@ex, @ex2, @detail].each { |p| expect(p.detail).to be_an_instance_of(Nokogiri::XML::NodeSet) }
|
64
|
-
end
|
65
|
-
it "detail NodeSet should have as many Nodes as there are <detail> elements in the xml" do
|
66
|
-
[@ex, @ex2, @detail].each { |p| expect(p.detail.size).to eq(1) }
|
67
|
-
end
|
68
|
-
it "should recognize type(_at) attribute on <detail> element" do
|
69
|
-
expect(@ex2.detail.type_at).to eq(['page number'])
|
70
|
-
expect(@detail.detail.type_at).to eq(['issue'])
|
71
|
-
end
|
72
|
-
it "should recognize level attribute on <detail> element" do
|
73
|
-
@mods_rec.from_str("<mods #{@ns_decl}><part><detail level='val'>anything</detail></part></mods>")
|
74
|
-
expect(@mods_rec.part.detail.level).to eq(['val'])
|
75
|
-
end
|
76
|
-
context "<number> child element" do
|
77
|
-
it "should be a NodeSet" do
|
78
|
-
[@ex, @ex2, @detail].each { |p| expect(p.detail.number).to be_an_instance_of(Nokogiri::XML::NodeSet) }
|
79
|
-
end
|
80
|
-
it "number NodeSet should have as many Nodes as there are <number> elements in the xml" do
|
81
|
-
[@ex2, @detail].each { |p| expect(p.detail.number.size).to eq(1) }
|
82
|
-
expect(@ex.detail.number.size).to eq(0)
|
83
|
-
end
|
84
|
-
it "text should get element value" do
|
85
|
-
expect(@ex2.detail.number.map { |n| n.text }).to eq(['3'])
|
86
|
-
expect(@detail.detail.number.map { |n| n.text }).to eq(['1'])
|
87
|
-
end
|
88
|
-
end # <number>
|
89
|
-
context "<caption> child element" do
|
90
|
-
before(:all) do
|
91
|
-
@mods_rec.from_str("<mods #{@ns_decl}><part><detail><caption>anything</caption></detail></part></mods>")
|
92
|
-
@caption = @mods_rec.part.detail.caption
|
93
|
-
end
|
94
|
-
it "should be a NodeSet" do
|
95
|
-
[@ex, @ex2, @detail].each { |p| expect(p.detail.caption).to be_an_instance_of(Nokogiri::XML::NodeSet) }
|
96
|
-
expect(@caption).to be_an_instance_of(Nokogiri::XML::NodeSet)
|
97
|
-
end
|
98
|
-
it "caption NodeSet should have as many Nodes as there are <caption> elements in the xml" do
|
99
|
-
[@ex, @ex2].each { |p| expect(p.detail.caption.size).to eq(0) }
|
100
|
-
expect(@detail.detail.caption.size).to eq(1)
|
101
|
-
expect(@caption.size).to eq(1)
|
102
|
-
end
|
103
|
-
it "text should get element value" do
|
104
|
-
expect(@detail.detail.caption.map { |n| n.text }).to eq(['no.'])
|
105
|
-
expect(@caption.map { |n| n.text }).to eq(['anything'])
|
106
|
-
end
|
107
|
-
end # <caption>
|
108
|
-
context "<title> child element" do
|
109
|
-
it "should be a NodeSet" do
|
110
|
-
[@ex, @ex2, @detail].each { |p| expect(p.detail.title).to be_an_instance_of(Nokogiri::XML::NodeSet) }
|
111
|
-
end
|
112
|
-
it "title NodeSet should have as many Nodes as there are <title> elements in the xml" do
|
113
|
-
expect(@ex.detail.title.size).to eq(1)
|
114
|
-
[@ex2, @detail].each { |p| expect(p.detail.title.size).to eq(0) }
|
115
|
-
end
|
116
|
-
it "text should get element value" do
|
117
|
-
expect(@ex.detail.title.map { |n| n.text }).to eq(['Wayfarers (Poem)'])
|
118
|
-
[@ex2, @detail].each { |p| expect(p.detail.title.map { |n| n.text }).to eq([]) }
|
119
|
-
end
|
120
|
-
end # <title>
|
121
|
-
end # <detail>
|
122
|
-
|
123
|
-
context "<extent> child element" do
|
124
|
-
it "should be a NodeSet" do
|
125
|
-
[@ex, @ex2, @detail].each { |p| expect(p.extent).to be_an_instance_of(Nokogiri::XML::NodeSet) }
|
126
|
-
end
|
127
|
-
it "extent NodeSet should have as many Nodes as there are <extent> elements in the xml" do
|
128
|
-
[@ex, @ex2].each { |p| expect(p.extent.size).to eq(1) }
|
129
|
-
expect(@detail.extent.size).to eq(0)
|
130
|
-
end
|
131
|
-
it "should recognize unit attribute on <extent> element" do
|
132
|
-
[@ex, @ex2].each { |p| expect(p.extent.unit).to eq(['pages']) }
|
133
|
-
end
|
134
|
-
context "<start> child element" do
|
135
|
-
it "should be a NodeSet" do
|
136
|
-
[@ex, @ex2, @detail].each { |p| expect(p.extent.start).to be_an_instance_of(Nokogiri::XML::NodeSet) }
|
137
|
-
end
|
138
|
-
it "start NodeSet should have as many Nodes as there are <start> elements in the xml" do
|
139
|
-
[@ex, @ex2].each { |p| expect(p.extent.start.size).to eq(1) }
|
140
|
-
expect(@detail.extent.start.size).to eq(0)
|
141
|
-
end
|
142
|
-
it "text should get element value" do
|
143
|
-
expect(@ex.extent.start.map { |n| n.text }).to eq(['97'])
|
144
|
-
expect(@ex2.extent.start.map { |n| n.text }).to eq(['3'])
|
145
|
-
end
|
146
|
-
end # <start>
|
147
|
-
context "<end> child element" do
|
148
|
-
it "should be a NodeSet" do
|
149
|
-
[@ex, @ex2, @detail].each { |p| expect(p.extent.end).to be_an_instance_of(Nokogiri::XML::NodeSet) }
|
150
|
-
end
|
151
|
-
it "end NodeSet should have as many Nodes as there are <end> elements in the xml" do
|
152
|
-
expect(@ex.extent.end.size).to eq(1)
|
153
|
-
[@ex2, @detail].each { |p| expect(p.extent.end.size).to eq(0) }
|
154
|
-
end
|
155
|
-
it "text should get element value" do
|
156
|
-
expect(@ex.extent.end.map { |n| n.text }).to eq(['98'])
|
157
|
-
end
|
158
|
-
end # <end>
|
159
|
-
context "<total> child element" do
|
160
|
-
before(:all) do
|
161
|
-
@mods_rec.from_str("<mods #{@ns_decl}><part><extent><total>anything</total></extent></part></mods>")
|
162
|
-
@total = @mods_rec.part.extent.total
|
163
|
-
end
|
164
|
-
it "should be a NodeSet" do
|
165
|
-
[@ex, @ex2, @detail].each { |p| expect(p.extent.total).to be_an_instance_of(Nokogiri::XML::NodeSet) }
|
166
|
-
expect(@total).to be_an_instance_of(Nokogiri::XML::NodeSet)
|
167
|
-
end
|
168
|
-
it "total NodeSet should have as many Nodes as there are <total> elements in the xml" do
|
169
|
-
[@ex, @ex2, @detail].each { |p| expect(p.extent.total.size).to eq(0) }
|
170
|
-
expect(@total.size).to eq(1)
|
171
|
-
end
|
172
|
-
it "text should get element value" do
|
173
|
-
expect(@total.map { |n| n.text }).to eq(['anything'])
|
174
|
-
end
|
175
|
-
end # <total>
|
176
|
-
context "<list> child element" do
|
177
|
-
before(:all) do
|
178
|
-
@mods_rec.from_str("<mods #{@ns_decl}><part><extent><list>anything</list></extent></part></mods>")
|
179
|
-
@list = @mods_rec.part.extent.list
|
180
|
-
end
|
181
|
-
it "should be a NodeSet" do
|
182
|
-
[@ex, @ex2, @detail].each { |p| expect(p.extent.list).to be_an_instance_of(Nokogiri::XML::NodeSet) }
|
183
|
-
expect(@list).to be_an_instance_of(Nokogiri::XML::NodeSet)
|
184
|
-
end
|
185
|
-
it "list NodeSet should have as many Nodes as there are <list> elements in the xml" do
|
186
|
-
[@ex, @ex2, @detail].each { |p| expect(p.extent.list.size).to eq(0) }
|
187
|
-
expect(@list.size).to eq(1)
|
188
|
-
end
|
189
|
-
it "text should get element value" do
|
190
|
-
expect(@list.map { |n| n.text }).to eq(['anything'])
|
191
|
-
end
|
192
|
-
end # <list>
|
193
|
-
end # <extent>
|
194
|
-
|
195
|
-
context "<date> child element" do
|
196
|
-
before(:all) do
|
197
|
-
@date = @mods_rec.from_str("<mods #{@ns_decl}><part><date encoding='w3cdtf'>1999</date></part></mods>").part.date
|
198
|
-
end
|
199
|
-
it "should be a NodeSet" do
|
200
|
-
[@ex, @ex2, @detail].each { |p| expect(p.date).to be_an_instance_of(Nokogiri::XML::NodeSet) }
|
201
|
-
expect(@date).to be_an_instance_of(Nokogiri::XML::NodeSet)
|
202
|
-
end
|
203
|
-
it "extent NodeSet should have as many Nodes as there are <extent> elements in the xml" do
|
204
|
-
[@ex, @ex2, @detail].each { |p| expect(p.date.size).to eq(0) }
|
205
|
-
expect(@date.size).to eq(1)
|
206
|
-
end
|
207
|
-
it "should recognize all date attributes except keyDate" do
|
208
|
-
Mods::DATE_ATTRIBS.reject { |n| n == 'keyDate' }.each { |a|
|
209
|
-
@mods_rec.from_str("<mods #{@ns_decl}><part><date #{a}='attr_val'>zzz</date></part></mods>")
|
210
|
-
expect(@mods_rec.part.date.send(a.to_sym)).to eq(['attr_val'])
|
211
|
-
}
|
212
|
-
end
|
213
|
-
it "should not recognize keyDate attribute" do
|
214
|
-
@mods_rec.from_str("<mods #{@ns_decl}><part><date keyDate='yes'>zzz</date></part></mods>")
|
215
|
-
expect { @mods_rec.part.date.keyDate }.to raise_error(NoMethodError, /undefined method.*keyDate/)
|
216
|
-
end
|
217
|
-
end # <date>
|
218
|
-
|
219
|
-
context "<text> child element as .text_el term" do
|
220
|
-
before(:all) do
|
221
|
-
@text_ns = @mods_rec.from_str("<mods #{@ns_decl}><part><text encoding='w3cdtf'>1999</text></part></mods>").part.text_el
|
222
|
-
end
|
223
|
-
it "should be a NodeSet" do
|
224
|
-
[@ex, @ex2, @detail].each { |p| expect(p.text_el).to be_an_instance_of(Nokogiri::XML::NodeSet) }
|
225
|
-
expect(@text_ns).to be_an_instance_of(Nokogiri::XML::NodeSet)
|
226
|
-
end
|
227
|
-
it "text_el NodeSet should have as many Nodes as there are <text> elements in the xml" do
|
228
|
-
[@ex, @ex2, @detail].each { |p| expect(p.text_el.size).to eq(0) }
|
229
|
-
expect(@text_ns.size).to eq(1)
|
230
|
-
end
|
231
|
-
it "should recognize displayLabel attribute" do
|
232
|
-
@mods_rec.from_str("<mods #{@ns_decl}><part><text displayLabel='foo'>zzz</text></part></mods>")
|
233
|
-
expect(@mods_rec.part.text_el.displayLabel).to eq(['foo'])
|
234
|
-
end
|
235
|
-
it "should recognize type(_at) attribute on <text> element" do
|
236
|
-
@mods_rec.from_str("<mods #{@ns_decl}><part><text type='bar'>anything</text></part></mods>")
|
237
|
-
expect(@mods_rec.part.text_el.type_at).to eq(['bar'])
|
238
|
-
end
|
239
|
-
end # <text>
|
240
|
-
end # WITH namespaces
|
241
|
-
|
242
|
-
context "WITHOUT namespaces" do
|
243
|
-
before(:all) do
|
244
|
-
@ex = @mods_rec.from_str("<mods><part>
|
245
|
-
<detail>
|
246
|
-
<title>Wayfarers (Poem)</title>
|
247
|
-
</detail>
|
248
|
-
<extent unit='pages'>
|
249
|
-
<start>97</start>
|
250
|
-
<end>98</end>
|
251
|
-
</extent>
|
252
|
-
</part></mods>", false).part
|
253
|
-
@ex2 = @mods_rec.from_str("<mods><part>
|
254
|
-
<detail type='page number'>
|
255
|
-
<number>3</number>
|
256
|
-
</detail>
|
257
|
-
<extent unit='pages'>
|
258
|
-
<start>3</start>
|
259
|
-
</extent>
|
260
|
-
</part></mods>", false).part
|
261
|
-
@detail = @mods_rec.from_str("<mods><part>
|
262
|
-
<detail type='issue'>
|
263
|
-
<number>1</number>
|
264
|
-
<caption>no.</caption>
|
265
|
-
</detail>
|
266
|
-
</part></mods>", false).part
|
267
|
-
end
|
268
|
-
|
269
|
-
it "should be a NodeSet" do
|
270
|
-
[@ex, @ex2, @detail].each { |p| expect(p).to be_an_instance_of(Nokogiri::XML::NodeSet) }
|
271
|
-
end
|
272
|
-
it "should have as many members as there are <part> elements in the xml" do
|
273
|
-
[@ex, @ex2, @detail].each { |p| expect(p.size).to eq(1) }
|
274
|
-
end
|
275
|
-
it "should recognize type(_at) attribute on <part> element" do
|
276
|
-
@mods_rec.from_str("<mods><part type='val'>anything</part></mods>", false)
|
277
|
-
expect(@mods_rec.part.type_at).to eq(['val'])
|
278
|
-
end
|
279
|
-
it "should recognize order attribute on <part> element" do
|
280
|
-
@mods_rec.from_str("<mods><part order='val'>anything</part></mods>", false)
|
281
|
-
expect(@mods_rec.part.order).to eq(['val'])
|
282
|
-
end
|
283
|
-
it "should recognize ID attribute on <part> element as id_at term" do
|
284
|
-
@mods_rec.from_str("<mods><part ID='val'>anything</part></mods>", false)
|
285
|
-
expect(@mods_rec.part.id_at).to eq(['val'])
|
286
|
-
end
|
287
|
-
|
288
|
-
context "<detail> child element" do
|
289
|
-
it "should be a NodeSet" do
|
290
|
-
[@ex, @ex2, @detail].each { |p| expect(p.detail).to be_an_instance_of(Nokogiri::XML::NodeSet) }
|
291
|
-
end
|
292
|
-
it "detail NodeSet should have as many Nodes as there are <detail> elements in the xml" do
|
293
|
-
[@ex, @ex2, @detail].each { |p| expect(p.detail.size).to eq(1) }
|
294
|
-
end
|
295
|
-
it "should recognize type(_at) attribute on <detail> element" do
|
296
|
-
expect(@ex2.detail.type_at).to eq(['page number'])
|
297
|
-
expect(@detail.detail.type_at).to eq(['issue'])
|
298
|
-
end
|
299
|
-
it "should recognize level attribute on <detail> element" do
|
300
|
-
@mods_rec.from_str("<mods><part><detail level='val'>anything</detail></part></mods>", false)
|
301
|
-
expect(@mods_rec.part.detail.level).to eq(['val'])
|
302
|
-
end
|
303
|
-
context "<number> child element" do
|
304
|
-
it "should be a NodeSet" do
|
305
|
-
[@ex, @ex2, @detail].each { |p| expect(p.detail.number).to be_an_instance_of(Nokogiri::XML::NodeSet) }
|
306
|
-
end
|
307
|
-
it "number NodeSet should have as many Nodes as there are <number> elements in the xml" do
|
308
|
-
[@ex2, @detail].each { |p| expect(p.detail.number.size).to eq(1) }
|
309
|
-
expect(@ex.detail.number.size).to eq(0)
|
310
|
-
end
|
311
|
-
it "text should get element value" do
|
312
|
-
expect(@ex2.detail.number.map { |n| n.text }).to eq(['3'])
|
313
|
-
expect(@detail.detail.number.map { |n| n.text }).to eq(['1'])
|
314
|
-
end
|
315
|
-
end # <number>
|
316
|
-
context "<caption> child element" do
|
317
|
-
before(:all) do
|
318
|
-
@mods_rec.from_str("<mods><part><detail><caption>anything</caption></detail></part></mods>", false)
|
319
|
-
@caption = @mods_rec.part.detail.caption
|
320
|
-
end
|
321
|
-
it "should be a NodeSet" do
|
322
|
-
[@ex, @ex2, @detail].each { |p| expect(p.detail.caption).to be_an_instance_of(Nokogiri::XML::NodeSet) }
|
323
|
-
expect(@caption).to be_an_instance_of(Nokogiri::XML::NodeSet)
|
324
|
-
end
|
325
|
-
it "caption NodeSet should have as many Nodes as there are <caption> elements in the xml" do
|
326
|
-
[@ex, @ex2].each { |p| expect(p.detail.caption.size).to eq(0) }
|
327
|
-
expect(@detail.detail.caption.size).to eq(1)
|
328
|
-
expect(@caption.size).to eq(1)
|
329
|
-
end
|
330
|
-
it "text should get element value" do
|
331
|
-
expect(@detail.detail.caption.map { |n| n.text }).to eq(['no.'])
|
332
|
-
expect(@caption.map { |n| n.text }).to eq(['anything'])
|
333
|
-
end
|
334
|
-
end # <caption>
|
335
|
-
context "<title> child element" do
|
336
|
-
it "should be a NodeSet" do
|
337
|
-
[@ex, @ex2, @detail].each { |p| expect(p.detail.title).to be_an_instance_of(Nokogiri::XML::NodeSet) }
|
338
|
-
end
|
339
|
-
it "title NodeSet should have as many Nodes as there are <title> elements in the xml" do
|
340
|
-
expect(@ex.detail.title.size).to eq(1)
|
341
|
-
[@ex2, @detail].each { |p| expect(p.detail.title.size).to eq(0) }
|
342
|
-
end
|
343
|
-
it "text should get element value" do
|
344
|
-
expect(@ex.detail.title.map { |n| n.text }).to eq(['Wayfarers (Poem)'])
|
345
|
-
[@ex2, @detail].each { |p| expect(p.detail.title.map { |n| n.text }).to eq([]) }
|
346
|
-
end
|
347
|
-
end # <title>
|
348
|
-
end # <detail>
|
349
|
-
|
350
|
-
context "<extent> child element" do
|
351
|
-
it "should be a NodeSet" do
|
352
|
-
[@ex, @ex2, @detail].each { |p| expect(p.extent).to be_an_instance_of(Nokogiri::XML::NodeSet) }
|
353
|
-
end
|
354
|
-
it "extent NodeSet should have as many Nodes as there are <extent> elements in the xml" do
|
355
|
-
[@ex, @ex2].each { |p| expect(p.extent.size).to eq(1) }
|
356
|
-
expect(@detail.extent.size).to eq(0)
|
357
|
-
end
|
358
|
-
it "should recognize unit attribute on <extent> element" do
|
359
|
-
[@ex, @ex2].each { |p| expect(p.extent.unit).to eq(['pages']) }
|
360
|
-
end
|
361
|
-
context "<start> child element" do
|
362
|
-
it "should be a NodeSet" do
|
363
|
-
[@ex, @ex2, @detail].each { |p| expect(p.extent.start).to be_an_instance_of(Nokogiri::XML::NodeSet) }
|
364
|
-
end
|
365
|
-
it "start NodeSet should have as many Nodes as there are <start> elements in the xml" do
|
366
|
-
[@ex, @ex2].each { |p| expect(p.extent.start.size).to eq(1) }
|
367
|
-
expect(@detail.extent.start.size).to eq(0)
|
368
|
-
end
|
369
|
-
it "text should get element value" do
|
370
|
-
expect(@ex.extent.start.map { |n| n.text }).to eq(['97'])
|
371
|
-
expect(@ex2.extent.start.map { |n| n.text }).to eq(['3'])
|
372
|
-
end
|
373
|
-
end # <start>
|
374
|
-
context "<end> child element" do
|
375
|
-
it "should be a NodeSet" do
|
376
|
-
[@ex, @ex2, @detail].each { |p| expect(p.extent.end).to be_an_instance_of(Nokogiri::XML::NodeSet) }
|
377
|
-
end
|
378
|
-
it "end NodeSet should have as many Nodes as there are <end> elements in the xml" do
|
379
|
-
expect(@ex.extent.end.size).to eq(1)
|
380
|
-
[@ex2, @detail].each { |p| expect(p.extent.end.size).to eq(0) }
|
381
|
-
end
|
382
|
-
it "text should get element value" do
|
383
|
-
expect(@ex.extent.end.map { |n| n.text }).to eq(['98'])
|
384
|
-
end
|
385
|
-
end # <end>
|
386
|
-
context "<total> child element" do
|
387
|
-
before(:all) do
|
388
|
-
@mods_rec.from_str("<mods><part><extent><total>anything</total></extent></part></mods>", false)
|
389
|
-
@total = @mods_rec.part.extent.total
|
390
|
-
end
|
391
|
-
it "should be a NodeSet" do
|
392
|
-
[@ex, @ex2, @detail].each { |p| expect(p.extent.total).to be_an_instance_of(Nokogiri::XML::NodeSet) }
|
393
|
-
expect(@total).to be_an_instance_of(Nokogiri::XML::NodeSet)
|
394
|
-
end
|
395
|
-
it "total NodeSet should have as many Nodes as there are <total> elements in the xml" do
|
396
|
-
[@ex, @ex2, @detail].each { |p| expect(p.extent.total.size).to eq(0) }
|
397
|
-
expect(@total.size).to eq(1)
|
398
|
-
end
|
399
|
-
it "text should get element value" do
|
400
|
-
expect(@total.map { |n| n.text }).to eq(['anything'])
|
401
|
-
end
|
402
|
-
end # <total>
|
403
|
-
context "<list> child element" do
|
404
|
-
before(:all) do
|
405
|
-
@mods_rec.from_str("<mods><part><extent><list>anything</list></extent></part></mods>", false)
|
406
|
-
@list = @mods_rec.part.extent.list
|
407
|
-
end
|
408
|
-
it "should be a NodeSet" do
|
409
|
-
[@ex, @ex2, @detail].each { |p| expect(p.extent.list).to be_an_instance_of(Nokogiri::XML::NodeSet) }
|
410
|
-
expect(@list).to be_an_instance_of(Nokogiri::XML::NodeSet)
|
411
|
-
end
|
412
|
-
it "list NodeSet should have as many Nodes as there are <list> elements in the xml" do
|
413
|
-
[@ex, @ex2, @detail].each { |p| expect(p.extent.list.size).to eq(0) }
|
414
|
-
expect(@list.size).to eq(1)
|
415
|
-
end
|
416
|
-
it "text should get element value" do
|
417
|
-
expect(@list.map { |n| n.text }).to eq(['anything'])
|
418
|
-
end
|
419
|
-
end # <list>
|
420
|
-
end # <extent>
|
421
|
-
|
422
|
-
context "<date> child element" do
|
423
|
-
before(:all) do
|
424
|
-
@date = @mods_rec.from_str("<mods><part><date encoding='w3cdtf'>1999</date></part></mods>", false).part.date
|
425
|
-
end
|
426
|
-
it "should be a NodeSet" do
|
427
|
-
[@ex, @ex2, @detail].each { |p| expect(p.date).to be_an_instance_of(Nokogiri::XML::NodeSet) }
|
428
|
-
expect(@date).to be_an_instance_of(Nokogiri::XML::NodeSet)
|
429
|
-
end
|
430
|
-
it "extent NodeSet should have as many Nodes as there are <extent> elements in the xml" do
|
431
|
-
[@ex, @ex2, @detail].each { |p| expect(p.date.size).to eq(0) }
|
432
|
-
expect(@date.size).to eq(1)
|
433
|
-
end
|
434
|
-
it "should recognize all date attributes except keyDate" do
|
435
|
-
Mods::DATE_ATTRIBS.reject { |n| n == 'keyDate' }.each { |a|
|
436
|
-
@mods_rec.from_str("<mods><part><date #{a}='attr_val'>zzz</date></part></mods>", false)
|
437
|
-
expect(@mods_rec.part.date.send(a.to_sym)).to eq(['attr_val'])
|
438
|
-
}
|
439
|
-
end
|
440
|
-
it "should not recognize keyDate attribute" do
|
441
|
-
@mods_rec.from_str("<mods><part><date keyDate='yes'>zzz</date></part></mods>", false)
|
442
|
-
expect { @mods_rec.part.date.keyDate }.to raise_error(NoMethodError, /undefined method.*keyDate/)
|
443
|
-
end
|
444
|
-
end # <date>
|
445
|
-
|
446
|
-
context "<text> child element as .text_el term" do
|
447
|
-
before(:all) do
|
448
|
-
@text_ns = @mods_rec.from_str("<mods><part><text encoding='w3cdtf'>1999</text></part></mods>", false).part.text_el
|
449
|
-
end
|
450
|
-
it "should be a NodeSet" do
|
451
|
-
[@ex, @ex2, @detail].each { |p| expect(p.text_el).to be_an_instance_of(Nokogiri::XML::NodeSet) }
|
452
|
-
expect(@text_ns).to be_an_instance_of(Nokogiri::XML::NodeSet)
|
453
|
-
end
|
454
|
-
it "text_el NodeSet should have as many Nodes as there are <text> elements in the xml" do
|
455
|
-
[@ex, @ex2, @detail].each { |p| expect(p.text_el.size).to eq(0) }
|
456
|
-
expect(@text_ns.size).to eq(1)
|
457
|
-
end
|
458
|
-
it "should recognize displayLabel attribute" do
|
459
|
-
@mods_rec.from_str("<mods><part><text displayLabel='foo'>zzz</text></part></mods>", false)
|
460
|
-
expect(@mods_rec.part.text_el.displayLabel).to eq(['foo'])
|
461
|
-
end
|
462
|
-
it "should recognize type(_at) attribute on <text> element" do
|
463
|
-
@mods_rec.from_str("<mods><part><text type='bar'>anything</text></part></mods>", false)
|
464
|
-
expect(@mods_rec.part.text_el.type_at).to eq(['bar'])
|
465
|
-
end
|
466
|
-
end # <text>
|
467
|
-
end # WITHOUT namespaces
|
468
|
-
|
469
|
-
|
470
|
-
end # basic <part> terminoology
|
471
|
-
end
|
@@ -1,144 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "Mods <physicalDescription> Element" do
|
4
|
-
before(:all) do
|
5
|
-
@mods_rec = Mods::Record.new
|
6
|
-
@ns_decl = "xmlns='#{Mods::MODS_NS}'"
|
7
|
-
end
|
8
|
-
|
9
|
-
context "basic physical_description terminology pieces" do
|
10
|
-
|
11
|
-
context "WITH namespaces" do
|
12
|
-
|
13
|
-
it "extent child element" do
|
14
|
-
@mods_rec.from_str("<mods #{@ns_decl}><physicalDescription><extent>extent</extent></physicalDescription></mods>")
|
15
|
-
expect(@mods_rec.physical_description.extent.map { |n| n.text }).to eq(["extent"])
|
16
|
-
end
|
17
|
-
|
18
|
-
context "note child element" do
|
19
|
-
before(:all) do
|
20
|
-
forms_and_notes = "<mods #{@ns_decl}><physicalDescription>
|
21
|
-
<form authority='aat'>Graphics</form>
|
22
|
-
<form>plain form</form>
|
23
|
-
<note displayLabel='Dimensions'>dimension text</note>
|
24
|
-
<note displayLabel='Condition'>condition text</note>
|
25
|
-
</physicalDescription></mods>"
|
26
|
-
@mods_rec.from_str(forms_and_notes)
|
27
|
-
end
|
28
|
-
it "should understand note element" do
|
29
|
-
expect(@mods_rec.physical_description.note.map { |n| n.text }).to eq(["dimension text", "condition text"])
|
30
|
-
end
|
31
|
-
it "should understand displayLabel attribute on note element" do
|
32
|
-
expect(@mods_rec.physical_description.note.displayLabel).to eq(["Dimensions", "Condition"])
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
context "form child element" do
|
37
|
-
before(:all) do
|
38
|
-
forms_and_extent = "<mods #{@ns_decl}><physicalDescription>
|
39
|
-
<form authority='smd'>map</form>
|
40
|
-
<form type='material'>foo</form>
|
41
|
-
<extent>1 map ; 22 x 18 cm.</extent>
|
42
|
-
</physicalDescription></mods>"
|
43
|
-
@mods_rec.from_str(forms_and_extent)
|
44
|
-
end
|
45
|
-
it "should understand form element" do
|
46
|
-
expect(@mods_rec.physical_description.form.map { |n| n.text }).to eq(["map", "foo"])
|
47
|
-
end
|
48
|
-
it "should understand authority attribute on form element" do
|
49
|
-
expect(@mods_rec.physical_description.form.authority).to eq(["smd"])
|
50
|
-
end
|
51
|
-
it "should understand type attribute on form element" do
|
52
|
-
expect(@mods_rec.physical_description.form.type_at).to eq(["material"])
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
context "digital materials" do
|
57
|
-
before(:all) do
|
58
|
-
digital = "<mods #{@ns_decl}><physicalDescription>
|
59
|
-
<reformattingQuality>preservation</reformattingQuality>
|
60
|
-
<internetMediaType>image/jp2</internetMediaType>
|
61
|
-
<digitalOrigin>reformatted digital</digitalOrigin>
|
62
|
-
</physicalDescription></mods>"
|
63
|
-
@mods_rec.from_str(digital)
|
64
|
-
end
|
65
|
-
it "should understand reformattingQuality child element" do
|
66
|
-
expect(@mods_rec.physical_description.reformattingQuality.map { |n| n.text }).to eq(["preservation"])
|
67
|
-
end
|
68
|
-
it "should understand digitalOrigin child element" do
|
69
|
-
expect(@mods_rec.physical_description.digitalOrigin.map { |n| n.text }).to eq(["reformatted digital"])
|
70
|
-
end
|
71
|
-
it "should understand internetMediaType child element" do
|
72
|
-
expect(@mods_rec.physical_description.internetMediaType.map { |n| n.text }).to eq(["image/jp2"])
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end # WITH namespaces
|
76
|
-
|
77
|
-
context "WITHOUT namespaces" do
|
78
|
-
it "extent child element" do
|
79
|
-
@mods_rec.from_str('<mods><physicalDescription><extent>extent</extent></physicalDescription></mods>', false)
|
80
|
-
expect(@mods_rec.physical_description.extent.map { |n| n.text }).to eq(["extent"])
|
81
|
-
end
|
82
|
-
|
83
|
-
context "note child element" do
|
84
|
-
before(:all) do
|
85
|
-
forms_and_notes = '<mods><physicalDescription>
|
86
|
-
<form authority="aat">Graphics</form>
|
87
|
-
<form>plain form</form>
|
88
|
-
<note displayLabel="Dimensions">dimension text</note>
|
89
|
-
<note displayLabel="Condition">condition text</note>
|
90
|
-
</physicalDescription></mods>'
|
91
|
-
@mods_rec.from_str(forms_and_notes, false)
|
92
|
-
end
|
93
|
-
it "should understand note element" do
|
94
|
-
expect(@mods_rec.physical_description.note.map { |n| n.text }).to eq(["dimension text", "condition text"])
|
95
|
-
end
|
96
|
-
it "should understand displayLabel attribute on note element" do
|
97
|
-
expect(@mods_rec.physical_description.note.displayLabel).to eq(["Dimensions", "Condition"])
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
context "form child element" do
|
102
|
-
before(:all) do
|
103
|
-
forms_and_extent = '<mods><physicalDescription>
|
104
|
-
<form authority="smd">map</form>
|
105
|
-
<form type="material">foo</form>
|
106
|
-
<extent>1 map ; 22 x 18 cm.</extent>
|
107
|
-
</physicalDescription></mods>'
|
108
|
-
@mods_rec.from_str(forms_and_extent, false)
|
109
|
-
end
|
110
|
-
it "should understand form element" do
|
111
|
-
expect(@mods_rec.physical_description.form.map { |n| n.text }).to eq(["map", "foo"])
|
112
|
-
end
|
113
|
-
it "should understand authority attribute on form element" do
|
114
|
-
expect(@mods_rec.physical_description.form.authority).to eq(["smd"])
|
115
|
-
end
|
116
|
-
it "should understand type attribute on form element" do
|
117
|
-
expect(@mods_rec.physical_description.form.type_at).to eq(["material"])
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
context "digital materials" do
|
122
|
-
before(:all) do
|
123
|
-
digital = '<mods><physicalDescription>
|
124
|
-
<reformattingQuality>preservation</reformattingQuality>
|
125
|
-
<internetMediaType>image/jp2</internetMediaType>
|
126
|
-
<digitalOrigin>reformatted digital</digitalOrigin>
|
127
|
-
</physicalDescription></mods>'
|
128
|
-
@mods_rec.from_str(digital, false)
|
129
|
-
end
|
130
|
-
it "should understand reformattingQuality child element" do
|
131
|
-
expect(@mods_rec.physical_description.reformattingQuality.map { |n| n.text }).to eq(["preservation"])
|
132
|
-
end
|
133
|
-
it "should understand digitalOrigin child element" do
|
134
|
-
expect(@mods_rec.physical_description.digitalOrigin.map { |n| n.text }).to eq(["reformatted digital"])
|
135
|
-
end
|
136
|
-
it "should understand internetMediaType child element" do
|
137
|
-
expect(@mods_rec.physical_description.internetMediaType.map { |n| n.text }).to eq(["image/jp2"])
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end # WITHOUT namespaces
|
141
|
-
|
142
|
-
end # basic terminology pieces
|
143
|
-
|
144
|
-
end
|