mods 0.0.15 → 0.0.16
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/README.rdoc +1 -0
- data/lib/mods/nom_terminology.rb +88 -10
- data/lib/mods/version.rb +1 -1
- data/mods.gemspec +1 -1
- data/spec/name_spec.rb +250 -35
- data/spec/subject_spec.rb +1 -1
- metadata +20 -4
data/.gitignore
CHANGED
data/README.rdoc
CHANGED
@@ -37,6 +37,7 @@ TODO: Write usage instructions here
|
|
37
37
|
|
38
38
|
== Releases
|
39
39
|
|
40
|
+
0.0.16 add role convenience methods (within name node)
|
40
41
|
0.0.15 make namespace aware processing the default
|
41
42
|
0.0.14 don't lose xml encoding in reader.normalize_mods under jruby
|
42
43
|
0.0.13 really really fix removal of xsi:schemaLocation in jruby
|
data/lib/mods/nom_terminology.rb
CHANGED
@@ -131,12 +131,49 @@ module Mods
|
|
131
131
|
n.displayForm :path => 'displayForm'
|
132
132
|
n.affiliation :path => 'affiliation'
|
133
133
|
n.description_el :path => 'description' # description is used by Nokogiri
|
134
|
-
n.role :path => 'role
|
135
|
-
r.
|
136
|
-
|
137
|
-
|
134
|
+
n.role :path => 'role' do |r|
|
135
|
+
r.roleTerm :path => 'roleTerm' do |rt|
|
136
|
+
rt.type_at :path => "@type", :accessor => lambda { |a| a.text }
|
137
|
+
Mods::AUTHORITY_ATTRIBS.each { |attr_name|
|
138
|
+
rt.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text }
|
139
|
+
}
|
140
|
+
end
|
141
|
+
# convenience method
|
142
|
+
r.authority :path => '.', :accessor => lambda { |role_node|
|
143
|
+
a = nil
|
144
|
+
role_node.roleTerm.each { |role_t|
|
145
|
+
# role_t.authority will be [] if it is missing from an earlier roleTerm
|
146
|
+
if role_t.authority && (!a || a.size == 0)
|
147
|
+
a = role_t.authority
|
148
|
+
end
|
149
|
+
}
|
150
|
+
a
|
151
|
+
}
|
152
|
+
# convenience method
|
153
|
+
r.code :path => '.', :accessor => lambda { |role_node|
|
154
|
+
c = nil
|
155
|
+
role_node.roleTerm.each { |role_t|
|
156
|
+
if role_t.type_at == 'code'
|
157
|
+
c ||= role_t.text
|
158
|
+
end
|
159
|
+
}
|
160
|
+
c
|
161
|
+
}
|
162
|
+
# convenience method
|
163
|
+
r.value :path => '.', :accessor => lambda { |role_node|
|
164
|
+
val = nil
|
165
|
+
role_node.roleTerm.each { |role_t|
|
166
|
+
if role_t.type_at == 'text'
|
167
|
+
val ||= role_t.text
|
168
|
+
end
|
169
|
+
}
|
170
|
+
# FIXME: this is broken if there are multiple role codes and some of them are not marcrelator
|
171
|
+
if !val && role_node.code && role_node.authority.first =~ /marcrelator/
|
172
|
+
val = MARC_RELATOR[role_node.code.first]
|
173
|
+
end
|
174
|
+
val
|
138
175
|
}
|
139
|
-
end
|
176
|
+
end # role node
|
140
177
|
end # t._plain_name
|
141
178
|
|
142
179
|
t.personal_name :path => '/mods/name[@type="personal"]'
|
@@ -583,12 +620,49 @@ module Mods
|
|
583
620
|
n.displayForm :path => 'm:displayForm'
|
584
621
|
n.affiliation :path => 'm:affiliation'
|
585
622
|
n.description_el :path => 'm:description' # description is used by Nokogiri
|
586
|
-
n.role :path => 'm:role
|
587
|
-
r.
|
588
|
-
|
589
|
-
|
623
|
+
n.role :path => 'm:role' do |r|
|
624
|
+
r.roleTerm :path => 'm:roleTerm' do |rt|
|
625
|
+
rt.type_at :path => "@type", :accessor => lambda { |a| a.text }
|
626
|
+
Mods::AUTHORITY_ATTRIBS.each { |attr_name|
|
627
|
+
rt.send attr_name, :path => "@#{attr_name}", :accessor => lambda { |a| a.text }
|
628
|
+
}
|
629
|
+
end
|
630
|
+
# convenience method
|
631
|
+
r.authority :path => '.', :accessor => lambda { |role_node|
|
632
|
+
a = nil
|
633
|
+
role_node.roleTerm.each { |role_t|
|
634
|
+
# role_t.authority will be [] if it is missing from an earlier roleTerm
|
635
|
+
if role_t.authority && (!a || a.size == 0)
|
636
|
+
a = role_t.authority
|
637
|
+
end
|
638
|
+
}
|
639
|
+
a
|
640
|
+
}
|
641
|
+
# convenience method
|
642
|
+
r.code :path => '.', :accessor => lambda { |role_node|
|
643
|
+
c = nil
|
644
|
+
role_node.roleTerm.each { |role_t|
|
645
|
+
if role_t.type_at == 'code'
|
646
|
+
c ||= role_t.text
|
647
|
+
end
|
648
|
+
}
|
649
|
+
c
|
650
|
+
}
|
651
|
+
# convenience method
|
652
|
+
r.value :path => '.', :accessor => lambda { |role_node|
|
653
|
+
val = nil
|
654
|
+
role_node.roleTerm.each { |role_t|
|
655
|
+
if role_t.type_at == 'text'
|
656
|
+
val ||= role_t.text
|
657
|
+
end
|
658
|
+
}
|
659
|
+
# FIXME: this is broken if there are multiple role codes and some of them are not marcrelator
|
660
|
+
if !val && role_node.code && role_node.authority.first =~ /marcrelator/
|
661
|
+
val = MARC_RELATOR[role_node.code.first]
|
662
|
+
end
|
663
|
+
val
|
590
664
|
}
|
591
|
-
end
|
665
|
+
end # role node
|
592
666
|
end # t._plain_name
|
593
667
|
|
594
668
|
t.personal_name :path => '/m:mods/m:name[@type="personal"]'
|
@@ -880,23 +954,27 @@ module Mods
|
|
880
954
|
n.nonSort :path => 'm:nonSort'
|
881
955
|
n.partNumber :path => 'm:partNumber'
|
882
956
|
n.partName :path => 'm:partName'
|
957
|
+
# convenience method
|
883
958
|
n.sort_title :path => '.', :accessor => lambda { |node|
|
884
959
|
if node.type_at != "alternative" || (node.type_at == "alternative" &&
|
885
960
|
mods_ng_xml.xpath('/m:mods/m:titleInfo', {'m' => Mods::MODS_NS}).size == 1)
|
886
961
|
node.title.text + (!node.subTitle.text.empty? ? "#{@title_delimiter}#{node.subTitle.text}" : "" )
|
887
962
|
end
|
888
963
|
}
|
964
|
+
# convenience method
|
889
965
|
n.full_title :path => '.', :accessor => lambda { |node|
|
890
966
|
(!node.nonSort.text.empty? ? "#{node.nonSort.text} " : "" ) +
|
891
967
|
node.title.text +
|
892
968
|
(!node.subTitle.text.empty? ? "#{@title_delimiter}#{node.subTitle.text}" : "" )
|
893
969
|
}
|
970
|
+
# convenience method
|
894
971
|
n.short_title :path => '.', :accessor => lambda { |node|
|
895
972
|
if node.type_at != "alternative"
|
896
973
|
(!node.nonSort.text.empty? ? "#{node.nonSort.text} " : "" ) +
|
897
974
|
node.title.text
|
898
975
|
end
|
899
976
|
}
|
977
|
+
# convenience method
|
900
978
|
n.alternative_title :path => '.', :accessor => lambda { |node|
|
901
979
|
if node.type_at == "alternative"
|
902
980
|
(!node.nonSort.text.empty? ? "#{node.nonSort.text} " : "" ) +
|
data/lib/mods/version.rb
CHANGED
data/mods.gemspec
CHANGED
data/spec/name_spec.rb
CHANGED
@@ -7,38 +7,31 @@ describe "Mods <name> Element" do
|
|
7
7
|
@ns_decl = "xmlns='#{Mods::MODS_NS}'"
|
8
8
|
|
9
9
|
@corp_name = 'ABC corp'
|
10
|
-
@mods_w_corp_name = "<mods><name type='corporate'><namePart>#{@corp_name}</namePart></name></mods>"
|
11
10
|
@mods_w_corp_name_ns = "<mods #{@ns_decl}><name type='corporate'><namePart>#{@corp_name}</namePart></name></mods>"
|
12
|
-
@
|
13
|
-
<role><roleTerm type='text'>lithographer</roleTerm></role></name></mods>"
|
11
|
+
@mods_w_corp_name = @mods_w_corp_name_ns.sub(" #{@ns_decl}", '')
|
14
12
|
@mods_w_corp_name_role_ns = "<mods #{@ns_decl}><name type='corporate'><namePart>#{@corp_name}</namePart>
|
15
13
|
<role><roleTerm type='text'>lithographer</roleTerm></role></name></mods>"
|
14
|
+
@mods_w_corp_name_role = @mods_w_corp_name_role_ns.sub(" #{@ns_decl}", '')
|
15
|
+
|
16
16
|
@pers_name = 'Crusty'
|
17
|
-
@mods_w_pers_name = "<mods><name type='personal'><namePart>#{@pers_name}</namePart></name></mods>"
|
18
17
|
@mods_w_pers_name_ns = "<mods #{@ns_decl}><name type='personal'><namePart>#{@pers_name}</namePart></name></mods>"
|
19
|
-
@
|
20
|
-
<name type='corporate'><namePart>#{@corp_name}</namePart></name>
|
21
|
-
<name type='personal'><namePart>#{@pers_name}</namePart></name></mods>"
|
18
|
+
@mods_w_pers_name = @mods_w_pers_name_ns.sub(" #{@ns_decl}", '')
|
22
19
|
@mods_w_both_ns = "<mods #{@ns_decl}>
|
23
20
|
<name type='corporate'><namePart>#{@corp_name}</namePart></name>
|
24
21
|
<name type='personal'><namePart>#{@pers_name}</namePart></name></mods>"
|
22
|
+
@mods_w_both = @mods_w_both_ns.sub(" #{@ns_decl}", '')
|
23
|
+
|
25
24
|
@pers_role = 'creator'
|
26
|
-
@mods_w_pers_name_role = "<mods><name type='personal'><namePart>#{@pers_name}</namePart>
|
27
|
-
<role><roleTerm authority='marcrelator' type='text'>#{@pers_role}</roleTerm><role></name></mods>"
|
28
25
|
@mods_w_pers_name_role_ns = "<mods #{@ns_decl}><name type='personal'><namePart>#{@pers_name}</namePart>
|
29
26
|
<role><roleTerm authority='marcrelator' type='text'>#{@pers_role}</roleTerm><role></name></mods>"
|
30
|
-
@
|
31
|
-
<namePart type='family'>Huston</namePart>
|
32
|
-
<role>
|
33
|
-
<roleTerm type='code' authority='marcrelator'>drt</roleTerm>
|
34
|
-
</role>
|
35
|
-
</name></mods>"
|
27
|
+
@mods_w_pers_name_role = @mods_w_pers_name_role_ns.sub(" #{@ns_decl}", '')
|
36
28
|
@mods_w_pers_name_role_code_ns = "<mods #{@ns_decl}><name type='personal'><namePart type='given'>John</namePart>
|
37
29
|
<namePart type='family'>Huston</namePart>
|
38
30
|
<role>
|
39
31
|
<roleTerm type='code' authority='marcrelator'>drt</roleTerm>
|
40
32
|
</role>
|
41
33
|
</name></mods>"
|
34
|
+
@mods_w_pers_name_role_code = @mods_w_pers_name_role_code_ns.sub(" #{@ns_decl}", '')
|
42
35
|
end
|
43
36
|
|
44
37
|
context "personal name" do
|
@@ -68,17 +61,17 @@ describe "Mods <name> Element" do
|
|
68
61
|
context "roles" do
|
69
62
|
it "should be possible to access a personal_name role easily" do
|
70
63
|
@mods_rec.from_str(@mods_w_pers_name_role_ns)
|
71
|
-
@mods_rec.personal_name.role.text.should include(@pers_role)
|
64
|
+
@mods_rec.personal_name.role.roleTerm.text.should include(@pers_role)
|
72
65
|
end
|
73
66
|
it "should get role type" do
|
74
67
|
@mods_rec.from_str(@mods_w_pers_name_role_ns)
|
75
|
-
@mods_rec.personal_name.role.type_at.should == ["text"]
|
68
|
+
@mods_rec.personal_name.role.roleTerm.type_at.should == ["text"]
|
76
69
|
@mods_rec.from_str(@mods_w_pers_name_role_code_ns)
|
77
|
-
@mods_rec.personal_name.role.type_at.should == ["code"]
|
70
|
+
@mods_rec.personal_name.role.roleTerm.type_at.should == ["code"]
|
78
71
|
end
|
79
72
|
it "should get role authority" do
|
80
73
|
@mods_rec.from_str(@mods_w_pers_name_role_ns)
|
81
|
-
@mods_rec.personal_name.role.authority.should == ["marcrelator"]
|
74
|
+
@mods_rec.personal_name.role.roleTerm.authority.should == ["marcrelator"]
|
82
75
|
end
|
83
76
|
end # roles
|
84
77
|
end # WITH namespaces
|
@@ -112,13 +105,13 @@ describe "Mods <name> Element" do
|
|
112
105
|
end
|
113
106
|
it "should get role type" do
|
114
107
|
@mods_rec.from_str(@mods_w_pers_name_role, false)
|
115
|
-
@mods_rec.personal_name.role.type_at.should == ["text"]
|
108
|
+
@mods_rec.personal_name.role.roleTerm.type_at.should == ["text"]
|
116
109
|
@mods_rec.from_str(@mods_w_pers_name_role_code, false)
|
117
|
-
@mods_rec.personal_name.role.type_at.should == ["code"]
|
110
|
+
@mods_rec.personal_name.role.roleTerm.type_at.should == ["code"]
|
118
111
|
end
|
119
112
|
it "should get role authority" do
|
120
113
|
@mods_rec.from_str(@mods_w_pers_name_role, false)
|
121
|
-
@mods_rec.personal_name.role.authority.should == ["marcrelator"]
|
114
|
+
@mods_rec.personal_name.role.roleTerm.authority.should == ["marcrelator"]
|
122
115
|
end
|
123
116
|
end # roles
|
124
117
|
end # WITHOUT namespaces
|
@@ -127,12 +120,6 @@ describe "Mods <name> Element" do
|
|
127
120
|
|
128
121
|
end # personal name
|
129
122
|
|
130
|
-
context "sort_author" do
|
131
|
-
it "should do something" do
|
132
|
-
pending "sort_author to be implemented (choose creator if present ... )"
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
123
|
context "corporate name" do
|
137
124
|
context "WITH namespaces" do
|
138
125
|
it "should recognize child elements" do
|
@@ -218,13 +205,13 @@ describe "Mods <name> Element" do
|
|
218
205
|
context "role child element" do
|
219
206
|
it "should get role type" do
|
220
207
|
@mods_rec.from_str(@mods_w_pers_name_role_ns)
|
221
|
-
@mods_rec.plain_name.role.type_at.should == ["text"]
|
208
|
+
@mods_rec.plain_name.role.roleTerm.type_at.should == ["text"]
|
222
209
|
@mods_rec.from_str(@mods_w_pers_name_role_code_ns)
|
223
|
-
@mods_rec.plain_name.role.type_at.should == ["code"]
|
210
|
+
@mods_rec.plain_name.role.roleTerm.type_at.should == ["code"]
|
224
211
|
end
|
225
212
|
it "should get role authority" do
|
226
213
|
@mods_rec.from_str(@mods_w_pers_name_role_ns)
|
227
|
-
@mods_rec.plain_name.role.authority.should == ["marcrelator"]
|
214
|
+
@mods_rec.plain_name.role.roleTerm.authority.should == ["marcrelator"]
|
228
215
|
end
|
229
216
|
end
|
230
217
|
|
@@ -262,22 +249,250 @@ describe "Mods <name> Element" do
|
|
262
249
|
context "role child element" do
|
263
250
|
it "should get role type" do
|
264
251
|
@mods_rec.from_str(@mods_w_pers_name_role, false)
|
265
|
-
@mods_rec.plain_name.role.type_at.should == ["text"]
|
252
|
+
@mods_rec.plain_name.role.roleTerm.type_at.should == ["text"]
|
266
253
|
@mods_rec.from_str(@mods_w_pers_name_role_code, false)
|
267
|
-
@mods_rec.plain_name.role.type_at.should == ["code"]
|
254
|
+
@mods_rec.plain_name.role.roleTerm.type_at.should == ["code"]
|
268
255
|
end
|
269
256
|
it "should get role authority" do
|
270
257
|
@mods_rec.from_str(@mods_w_pers_name_role, false)
|
271
|
-
@mods_rec.plain_name.role.authority.should == ["marcrelator"]
|
258
|
+
@mods_rec.plain_name.role.roleTerm.authority.should == ["marcrelator"]
|
272
259
|
end
|
273
260
|
end
|
274
261
|
end # context WITHOUT namespaces
|
275
262
|
|
276
263
|
end # plain name
|
277
|
-
|
278
264
|
|
279
265
|
it "should be able to translate the marc relator code into text" do
|
280
266
|
MARC_RELATOR['drt'].should == "Director"
|
281
267
|
end
|
282
268
|
|
269
|
+
context "roles" do
|
270
|
+
before(:all) do
|
271
|
+
@xml_w_code = "<mods #{@ns_decl}><name><namePart>Alfred Hitchock</namePart>
|
272
|
+
<role><roleTerm type='code' authority='marcrelator'>drt</roleTerm></role>
|
273
|
+
</name></mods>"
|
274
|
+
@xml_w_text = "<mods #{@ns_decl}><name><namePart>Sean Connery</namePart>
|
275
|
+
<role><roleTerm type='text' authority='marcrelator'>Actor</roleTerm></role>
|
276
|
+
</name></mods>"
|
277
|
+
@xml_wo_authority = "<mods #{@ns_decl}><name><namePart>Exciting Prints</namePart>
|
278
|
+
<role><roleTerm type='text'>lithographer</roleTerm></role>
|
279
|
+
</name></mods>"
|
280
|
+
@xml_w_both = "<mods #{@ns_decl}><name><namePart>anyone</namePart>
|
281
|
+
<role>
|
282
|
+
<roleTerm type='text' authority='marcrelator'>CreatorFake</roleTerm>
|
283
|
+
<roleTerm type='code' authority='marcrelator'>cre</roleTerm>
|
284
|
+
</role>
|
285
|
+
</name></mods>"
|
286
|
+
@xml_w_mult_roles = "<mods #{@ns_decl}><name><namePart>Fats Waller</namePart>
|
287
|
+
<role><roleTerm type='text'>Creator</roleTerm>
|
288
|
+
<roleTerm type='code' authority='marcrelator'>cre</roleTerm></role>
|
289
|
+
<role><roleTerm type='text'>Performer</roleTerm></role>
|
290
|
+
</name></mods>"
|
291
|
+
end
|
292
|
+
|
293
|
+
context "convenience methods WITH namespaces" do
|
294
|
+
before(:all) do
|
295
|
+
@mods_w_code = Mods::Record.new.from_str(@xml_w_code)
|
296
|
+
@mods_w_text = Mods::Record.new.from_str(@xml_w_text)
|
297
|
+
@mods_wo_authority = Mods::Record.new.from_str(@xml_wo_authority)
|
298
|
+
@mods_w_both = Mods::Record.new.from_str(@xml_w_both)
|
299
|
+
@mods_mult_roles = Mods::Record.new.from_str(@xml_w_mult_roles)
|
300
|
+
end
|
301
|
+
context "value" do
|
302
|
+
it "should be the value of a text roleTerm" do
|
303
|
+
@mods_w_text.plain_name.role.value.should == ["Actor"]
|
304
|
+
end
|
305
|
+
it "should be the translation of the code if it is a marcrelator code and there is no text roleTerm" do
|
306
|
+
@mods_w_code.plain_name.role.value.should == ["Director"]
|
307
|
+
end
|
308
|
+
it "should be the value of the text roleTerm if there are both a code and a text roleTerm" do
|
309
|
+
@mods_w_both.plain_name.role.value.should == ["CreatorFake"]
|
310
|
+
end
|
311
|
+
it "should have 2 values if there are 2 role elements" do
|
312
|
+
@mods_mult_roles.plain_name.role.value.should == ['Creator', 'Performer']
|
313
|
+
end
|
314
|
+
end
|
315
|
+
context "authority" do
|
316
|
+
it "should be empty if it is missing from xml" do
|
317
|
+
@mods_wo_authority.plain_name.role.authority.size.should == 0
|
318
|
+
end
|
319
|
+
it "should be the value of the authority attribute on the roleTerm element" do
|
320
|
+
@mods_w_code.plain_name.role.authority.should == ["marcrelator"]
|
321
|
+
@mods_w_text.plain_name.role.authority.should == ["marcrelator"]
|
322
|
+
@mods_w_both.plain_name.role.authority.should == ["marcrelator"]
|
323
|
+
end
|
324
|
+
end
|
325
|
+
context "code" do
|
326
|
+
it "should be empty if the roleTerm is not of type code" do
|
327
|
+
@mods_w_text.plain_name.role.code.size.should == 0
|
328
|
+
@mods_wo_authority.plain_name.role.code.size.should == 0
|
329
|
+
end
|
330
|
+
it "should be the value of the roleTerm element if element's type attribute is 'code'" do
|
331
|
+
@mods_w_code.plain_name.role.code.should == ["drt"]
|
332
|
+
@mods_w_both.plain_name.role.code.should == ["cre"]
|
333
|
+
end
|
334
|
+
end
|
335
|
+
context "pertaining to a specific name" do
|
336
|
+
before(:all) do
|
337
|
+
complex = "<mods #{@ns_decl}>
|
338
|
+
<name>
|
339
|
+
<namePart>Sean Connery</namePart>
|
340
|
+
<role><roleTerm type='code' authority='marcrelator'>drt</roleTerm></role>
|
341
|
+
</name>
|
342
|
+
<name>
|
343
|
+
<namePart>Pierce Brosnan</namePart>
|
344
|
+
<role>
|
345
|
+
<roleTerm type='text'>CreatorFake</roleTerm>
|
346
|
+
<roleTerm type='code' authority='marcrelator'>cre</roleTerm>
|
347
|
+
</role>
|
348
|
+
<role><roleTerm type='text' authority='marcrelator'>Actor</roleTerm></role>
|
349
|
+
</name>
|
350
|
+
<name>
|
351
|
+
<namePart>Daniel Craig</namePart>
|
352
|
+
<role>
|
353
|
+
<roleTerm type='text' authority='marcrelator'>Actor</roleTerm>
|
354
|
+
<roleTerm type='code' authority='marcrelator'>cre</roleTerm>
|
355
|
+
</role>
|
356
|
+
</name>
|
357
|
+
</mods>"
|
358
|
+
@mods_complex = Mods::Record.new.from_str(complex)
|
359
|
+
end
|
360
|
+
it "roles should be empty array when there is no role element" do
|
361
|
+
@mods_rec.from_str(@mods_w_pers_name_ns)
|
362
|
+
@mods_rec.personal_name.first.role.size.should == 0
|
363
|
+
end
|
364
|
+
it "object should have same number of roles as it has role nodes in xml" do
|
365
|
+
@mods_complex.plain_name[0].role.size.should == 1
|
366
|
+
@mods_complex.plain_name[1].role.size.should == 2
|
367
|
+
@mods_complex.plain_name[2].role.size.should == 1
|
368
|
+
end
|
369
|
+
context "name's roles should be correctly populated" do
|
370
|
+
it "text attribute" do
|
371
|
+
@mods_complex.plain_name[0].role.value.should == ['Director']
|
372
|
+
@mods_complex.plain_name[1].role.value.should == ['CreatorFake', 'Actor']
|
373
|
+
@mods_complex.plain_name[2].role.value.should == ['Actor']
|
374
|
+
end
|
375
|
+
it "code attribute" do
|
376
|
+
@mods_complex.plain_name[0].role.code.should == ['drt']
|
377
|
+
@mods_complex.plain_name[1].role.code.should == ['cre']
|
378
|
+
@mods_complex.plain_name[2].role.code.should == ['cre']
|
379
|
+
end
|
380
|
+
it "authority attribute" do
|
381
|
+
@mods_complex.plain_name[0].role.authority.should == ['marcrelator']
|
382
|
+
@mods_complex.plain_name[1].role.authority.should == ['marcrelator', 'marcrelator']
|
383
|
+
@mods_complex.plain_name[2].role.authority.should == ['marcrelator']
|
384
|
+
end
|
385
|
+
it "multiple roles" do
|
386
|
+
@mods_mult_roles.plain_name.first.role.value.should == ['Creator', 'Performer']
|
387
|
+
@mods_mult_roles.plain_name.first.role.code.should == ['cre']
|
388
|
+
@mods_mult_roles.plain_name.role.first.roleTerm.authority.first.should == 'marcrelator'
|
389
|
+
@mods_mult_roles.plain_name.role.last.roleTerm.authority.size.should == 0
|
390
|
+
end
|
391
|
+
end
|
392
|
+
end # pertaining to a specific name
|
393
|
+
end # roles WITH namespaces
|
394
|
+
|
395
|
+
context "convenience methods WITHOUT namespaces" do
|
396
|
+
before(:all) do
|
397
|
+
@mods_w_code = Mods::Record.new.from_str(@xml_w_code.sub(" #{@ns_decl}", ''), false)
|
398
|
+
@mods_w_text = Mods::Record.new.from_str(@xml_w_text.sub(" #{@ns_decl}", ''), false)
|
399
|
+
@mods_wo_authority = Mods::Record.new.from_str(@xml_wo_authority.sub(" #{@ns_decl}", ''), false)
|
400
|
+
@mods_w_both = Mods::Record.new.from_str(@xml_w_both.sub(" #{@ns_decl}", ''), false)
|
401
|
+
@mods_mult_roles = Mods::Record.new.from_str(@xml_w_mult_roles.sub(" #{@ns_decl}", ''), false)
|
402
|
+
end
|
403
|
+
context "value" do
|
404
|
+
it "should be the value of a text roleTerm" do
|
405
|
+
@mods_w_text.plain_name.role.value.should == ["Actor"]
|
406
|
+
end
|
407
|
+
it "should be the translation of the code if it is a marcrelator code and there is no text roleTerm" do
|
408
|
+
@mods_w_code.plain_name.role.value.should == ["Director"]
|
409
|
+
end
|
410
|
+
it "should be the value of the text roleTerm if there are both a code and a text roleTerm" do
|
411
|
+
@mods_w_both.plain_name.role.value.should == ["CreatorFake"]
|
412
|
+
end
|
413
|
+
it "should have 2 values if there are 2 role elements" do
|
414
|
+
@mods_mult_roles.plain_name.role.value.should == ['Creator', 'Performer']
|
415
|
+
end
|
416
|
+
end
|
417
|
+
context "authority" do
|
418
|
+
it "should be empty if it is missing from xml" do
|
419
|
+
@mods_wo_authority.plain_name.role.authority.size.should == 0
|
420
|
+
end
|
421
|
+
it "should be the value of the authority attribute on the roleTerm element" do
|
422
|
+
@mods_w_code.plain_name.role.authority.should == ["marcrelator"]
|
423
|
+
@mods_w_text.plain_name.role.authority.should == ["marcrelator"]
|
424
|
+
@mods_w_both.plain_name.role.authority.should == ["marcrelator"]
|
425
|
+
end
|
426
|
+
end
|
427
|
+
context "code" do
|
428
|
+
it "should be empty if the roleTerm is not of type code" do
|
429
|
+
@mods_w_text.plain_name.role.code.size.should == 0
|
430
|
+
@mods_wo_authority.plain_name.role.code.size.should == 0
|
431
|
+
end
|
432
|
+
it "should be the value of the roleTerm element if element's type attribute is 'code'" do
|
433
|
+
@mods_w_code.plain_name.role.code.should == ["drt"]
|
434
|
+
@mods_w_both.plain_name.role.code.should == ["cre"]
|
435
|
+
end
|
436
|
+
end
|
437
|
+
context "pertaining to a specific name" do
|
438
|
+
before(:all) do
|
439
|
+
complex = "<mods>
|
440
|
+
<name>
|
441
|
+
<namePart>Sean Connery</namePart>
|
442
|
+
<role><roleTerm type='code' authority='marcrelator'>drt</roleTerm></role>
|
443
|
+
</name>
|
444
|
+
<name>
|
445
|
+
<namePart>Pierce Brosnan</namePart>
|
446
|
+
<role>
|
447
|
+
<roleTerm type='text'>CreatorFake</roleTerm>
|
448
|
+
<roleTerm type='code' authority='marcrelator'>cre</roleTerm>
|
449
|
+
</role>
|
450
|
+
<role><roleTerm type='text' authority='marcrelator'>Actor</roleTerm></role>
|
451
|
+
</name>
|
452
|
+
<name>
|
453
|
+
<namePart>Daniel Craig</namePart>
|
454
|
+
<role>
|
455
|
+
<roleTerm type='text' authority='marcrelator'>Actor</roleTerm>
|
456
|
+
<roleTerm type='code' authority='marcrelator'>cre</roleTerm>
|
457
|
+
</role>
|
458
|
+
</name>
|
459
|
+
</mods>"
|
460
|
+
@mods_complex = Mods::Record.new.from_str(complex, false)
|
461
|
+
end
|
462
|
+
it "roles should be empty array when there is no role element" do
|
463
|
+
@mods_rec.from_str(@mods_w_pers_name_ns)
|
464
|
+
@mods_rec.personal_name.first.role.size.should == 0
|
465
|
+
end
|
466
|
+
it "object should have same number of roles as it has role nodes in xml" do
|
467
|
+
@mods_complex.plain_name[0].role.size.should == 1
|
468
|
+
@mods_complex.plain_name[1].role.size.should == 2
|
469
|
+
@mods_complex.plain_name[2].role.size.should == 1
|
470
|
+
end
|
471
|
+
context "name's roles should be correctly populated" do
|
472
|
+
it "text attribute" do
|
473
|
+
@mods_complex.plain_name[0].role.value.should == ['Director']
|
474
|
+
@mods_complex.plain_name[1].role.value.should == ['CreatorFake', 'Actor']
|
475
|
+
@mods_complex.plain_name[2].role.value.should == ['Actor']
|
476
|
+
end
|
477
|
+
it "code attribute" do
|
478
|
+
@mods_complex.plain_name[0].role.code.should == ['drt']
|
479
|
+
@mods_complex.plain_name[1].role.code.should == ['cre']
|
480
|
+
@mods_complex.plain_name[2].role.code.should == ['cre']
|
481
|
+
end
|
482
|
+
it "authority attribute" do
|
483
|
+
@mods_complex.plain_name[0].role.authority.should == ['marcrelator']
|
484
|
+
@mods_complex.plain_name[1].role.authority.should == ['marcrelator', 'marcrelator']
|
485
|
+
@mods_complex.plain_name[2].role.authority.should == ['marcrelator']
|
486
|
+
end
|
487
|
+
it "multiple roles" do
|
488
|
+
@mods_mult_roles.plain_name.first.role.value.should == ['Creator', 'Performer']
|
489
|
+
@mods_mult_roles.plain_name.first.role.code.should == ['cre']
|
490
|
+
@mods_mult_roles.plain_name.role.first.roleTerm.authority.first.should == 'marcrelator'
|
491
|
+
@mods_mult_roles.plain_name.role.last.roleTerm.authority.size.should == 0
|
492
|
+
end
|
493
|
+
end
|
494
|
+
end # pertaining to a specific name
|
495
|
+
end # WITHOUT namespaces
|
496
|
+
end # roles
|
497
|
+
|
283
498
|
end
|
data/spec/subject_spec.rb
CHANGED
@@ -99,7 +99,7 @@ describe "Mods <subject> Element" do
|
|
99
99
|
@pers_name_sub.personal_name.displayForm.map { |e| e.text }.should == ['Edward VI , king of England, 1537-1553']
|
100
100
|
end
|
101
101
|
it "should be able to identify roles associated with a name" do
|
102
|
-
@mult_corp_name_sub.corporate_name.role.map { |e| e.text }.should == ['lithographers.']
|
102
|
+
@mult_corp_name_sub.corporate_name.role.roleTerm.map { |e| e.text }.should == ['lithographers.']
|
103
103
|
end
|
104
104
|
it "should be able to identify dates associated with a name" do
|
105
105
|
@mult_pers_name_sub.personal_name.date.map { |e| e.text }.should include("1818-1878")
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mods
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.16
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-12-18 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: nokogiri
|
@@ -156,6 +156,22 @@ dependencies:
|
|
156
156
|
- - ! '>='
|
157
157
|
- !ruby/object:Gem::Version
|
158
158
|
version: '0'
|
159
|
+
- !ruby/object:Gem::Dependency
|
160
|
+
name: equivalent-xml
|
161
|
+
requirement: !ruby/object:Gem::Requirement
|
162
|
+
none: false
|
163
|
+
requirements:
|
164
|
+
- - ! '>='
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
type: :development
|
168
|
+
prerelease: false
|
169
|
+
version_requirements: !ruby/object:Gem::Requirement
|
170
|
+
none: false
|
171
|
+
requirements:
|
172
|
+
- - ! '>='
|
173
|
+
- !ruby/object:Gem::Version
|
174
|
+
version: '0'
|
159
175
|
description: Parse MODS (Metadata Object Description Schema) records. More information
|
160
176
|
about MODS can be found at http://www.loc.gov/standards/mods/
|
161
177
|
email:
|
@@ -214,7 +230,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
214
230
|
version: '0'
|
215
231
|
segments:
|
216
232
|
- 0
|
217
|
-
hash:
|
233
|
+
hash: -1181909657495840648
|
218
234
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
219
235
|
none: false
|
220
236
|
requirements:
|
@@ -223,7 +239,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
223
239
|
version: '0'
|
224
240
|
segments:
|
225
241
|
- 0
|
226
|
-
hash:
|
242
|
+
hash: -1181909657495840648
|
227
243
|
requirements: []
|
228
244
|
rubyforge_project:
|
229
245
|
rubygems_version: 1.8.24
|