mods 2.4.1 → 3.0.1

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.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +24 -0
  3. data/.gitignore +1 -0
  4. data/README.md +0 -1
  5. data/lib/mods/date.rb +54 -17
  6. data/lib/mods/marc_country_codes.rb +12 -10
  7. data/lib/mods/nom_terminology.rb +109 -845
  8. data/lib/mods/reader.rb +9 -39
  9. data/lib/mods/record.rb +13 -28
  10. data/lib/mods/version.rb +1 -1
  11. data/mods.gemspec +2 -2
  12. data/spec/fixture_data/hp566jq8781.xml +334 -0
  13. data/spec/integration/parker_spec.rb +217 -0
  14. data/spec/{date_spec.rb → lib/date_spec.rb} +9 -1
  15. data/spec/lib/language_spec.rb +123 -0
  16. data/spec/lib/location_spec.rb +175 -0
  17. data/spec/lib/name_spec.rb +368 -0
  18. data/spec/lib/origin_info_spec.rb +134 -0
  19. data/spec/lib/part_spec.rb +162 -0
  20. data/spec/lib/physical_description_spec.rb +72 -0
  21. data/spec/{reader_spec.rb → lib/reader_spec.rb} +1 -41
  22. data/spec/lib/record_info_spec.rb +114 -0
  23. data/spec/lib/record_spec.rb +287 -0
  24. data/spec/lib/related_item_spec.rb +124 -0
  25. data/spec/lib/subject_spec.rb +427 -0
  26. data/spec/lib/title_spec.rb +108 -0
  27. data/spec/lib/top_level_elmnts_simple_spec.rb +169 -0
  28. data/spec/spec_helper.rb +86 -5
  29. data/spec/support/fixtures.rb +9 -0
  30. metadata +49 -44
  31. data/.travis.yml +0 -16
  32. data/spec/language_spec.rb +0 -118
  33. data/spec/location_spec.rb +0 -295
  34. data/spec/name_spec.rb +0 -759
  35. data/spec/origin_info_spec.rb +0 -447
  36. data/spec/part_spec.rb +0 -471
  37. data/spec/physical_description_spec.rb +0 -144
  38. data/spec/record_info_spec.rb +0 -493
  39. data/spec/record_spec.rb +0 -356
  40. data/spec/related_item_spec.rb +0 -305
  41. data/spec/subject_spec.rb +0 -809
  42. data/spec/title_spec.rb +0 -226
  43. data/spec/top_level_elmnts_simple_spec.rb +0 -369
data/spec/title_spec.rb DELETED
@@ -1,226 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "Mods <titleInfo> element" do
4
-
5
- before(:all) do
6
- @mods_rec = Mods::Record.new
7
- @ns_decl = "xmlns='#{Mods::MODS_NS}'"
8
- end
9
-
10
- context "WITH namespaces" do
11
-
12
- it "should recognize type attribute on titleInfo element" do
13
- Mods::TitleInfo::TYPES.each { |t|
14
- @mods_rec.from_str("<mods #{@ns_decl}><titleInfo type='#{t}'>hi</titleInfo></mods>")
15
- expect(@mods_rec.title_info.type_at).to eq([t])
16
- }
17
- end
18
- it "should recognize subelements" do
19
- Mods::TitleInfo::CHILD_ELEMENTS.each { |e|
20
- @mods_rec.from_str("<mods #{@ns_decl}><titleInfo><#{e}>oofda</#{e}></titleInfo></mods>")
21
- expect(@mods_rec.title_info.send(e).text).to eq('oofda')
22
- }
23
- end
24
-
25
- context "short_title" do
26
- it "should start with nonSort element" do
27
- @mods_rec.from_str("<mods #{@ns_decl}><titleInfo><title>Jerk</title><nonSort>The</nonSort></titleInfo></mods>")
28
- expect(@mods_rec.title_info.short_title).to eq(["The Jerk"])
29
- end
30
- it "should not include subtitle" do
31
- @mods_rec.from_str("<mods #{@ns_decl}><titleInfo><title>Jerk</title><subTitle>A Tale of Tourettes</subTitle><nonSort>The</nonSort></titleInfo></mods>")
32
- expect(@mods_rec.title_info.short_title).to eq(["The Jerk"])
33
- end
34
- it "Mods::Record.short_titles convenience method should return an Array (multiple titles are legal in Mods)" do
35
- @mods_rec.from_str("<mods #{@ns_decl}><titleInfo><title>Jerk</title><nonSort>The</nonSort></titleInfo><titleInfo><title>Joke</title></titleInfo></mods>")
36
- expect(@mods_rec.short_titles).to eq(["The Jerk", "Joke"])
37
- end
38
- it "should not include alternative titles" do
39
- @mods_rec.from_str("<mods #{@ns_decl}><titleInfo type='alternative'><title>ta da!</title></titleInfo></mods>")
40
- expect(@mods_rec.short_titles).not_to include("ta da!")
41
- @mods_rec.from_str("<mods #{@ns_decl}><titleInfo type='alternative'><title>1</title></titleInfo><titleInfo><title>2</title></titleInfo></mods>")
42
- expect(@mods_rec.short_titles).to eq(['2'])
43
- end
44
- # note that Mods::Record.short_title tests are in record_spec
45
- end
46
-
47
- context "full_title" do
48
- it "should start with nonSort element" do
49
- @mods_rec.from_str("<mods #{@ns_decl}><titleInfo><title>Jerk</title><nonSort>The</nonSort></titleInfo></mods>")
50
- expect(@mods_rec.title_info.full_title).to eq(["The Jerk"])
51
- end
52
- it "should include subtitle" do
53
- @mods_rec.from_str("<mods #{@ns_decl}><titleInfo><title>Jerk</title><subTitle>A Tale of Tourettes</subTitle><nonSort>The</nonSort></titleInfo></mods>")
54
- expect(@mods_rec.title_info.full_title).to eq(["The Jerk A Tale of Tourettes"])
55
- end
56
- it "Mods::Record.full_titles convenience method should return an Array (multiple titles are legal in Mods)" do
57
- @mods_rec.from_str("<mods #{@ns_decl}><titleInfo><title>Jerk</title><nonSort>The</nonSort></titleInfo><titleInfo><title>Joke</title></titleInfo></mods>")
58
- expect(@mods_rec.full_titles).to eq(["The Jerk", "Joke"])
59
- end
60
- # note that Mods::Record.full_title tests are in record_spec
61
- end
62
-
63
- context "sort_title" do
64
- it "should skip nonSort element" do
65
- @mods_rec.from_str("<mods #{@ns_decl}><titleInfo><title>Jerk</title><nonSort>The</nonSort></titleInfo></mods>")
66
- expect(@mods_rec.title_info.sort_title).to eq(["Jerk"])
67
- end
68
- it "should contain title and subtitle" do
69
- @mods_rec.from_str("<mods #{@ns_decl}><titleInfo><title>Jerk</title><subTitle>A Tale of Tourettes</subTitle><nonSort>The</nonSort></titleInfo></mods>")
70
- expect(@mods_rec.title_info.sort_title).to eq(["Jerk A Tale of Tourettes"])
71
- end
72
- it "should be an alternative title if there are no other choices" do
73
- @mods_rec.from_str("<mods #{@ns_decl}><titleInfo type='alternative'><title>1</title></titleInfo></mods>")
74
- expect(@mods_rec.title_info.sort_title).to eq(['1'])
75
- end
76
- it "should not be an alternative title if there are other choices" do
77
- @mods_rec.from_str("<mods #{@ns_decl}><titleInfo type='alternative'><title>1</title></titleInfo><titleInfo><title>2</title></titleInfo></mods>")
78
- expect(@mods_rec.title_info.sort_title).to eq(['2'])
79
- expect(@mods_rec.sort_title).to eq('2')
80
- end
81
- it "should have a configurable delimiter between title and subtitle" do
82
- m = Mods::Record.new(' : ')
83
- m.from_str("<mods #{@ns_decl}><titleInfo><title>Jerk</title><subTitle>A Tale of Tourettes</subTitle><nonSort>The</nonSort></titleInfo></mods>")
84
- expect(m.title_info.sort_title).to eq(["Jerk : A Tale of Tourettes"])
85
- end
86
- context "Mods::Record.sort_title convenience method" do
87
- it "convenience method sort_title in Mods::Record should return a string" do
88
- @mods_rec.from_str("<mods #{@ns_decl}><titleInfo><title>Jerk</title><subTitle>A Tale of Tourettes</subTitle><nonSort>The</nonSort></titleInfo></mods>")
89
- expect(@mods_rec.sort_title).to eq("Jerk A Tale of Tourettes")
90
- end
91
- end
92
- # note that Mods::Record.sort_title tests are in record_spec
93
- end
94
-
95
- context "alternative_title" do
96
- it "should get an alternative title, if it exists" do
97
- @mods_rec.from_str("<mods #{@ns_decl}><titleInfo type='alternative'><title>ta da!</title></titleInfo></mods>")
98
- expect(@mods_rec.title_info.alternative_title).to eq(["ta da!"])
99
- end
100
- it "Mods::Record.alternative_titles convenience method for getting an Array of alternative titles when there are multiple elements" do
101
- @mods_rec.from_str("<mods #{@ns_decl}><titleInfo type='alternative'><title>1</title></titleInfo><titleInfo type='alternative'><title>2</title></titleInfo></mods>")
102
- expect(@mods_rec.alternative_titles).to eq(['1', '2'])
103
- @mods_rec.from_str("<mods #{@ns_decl}><titleInfo type='alternative'><title>1</title><title>2</title></titleInfo></mods>")
104
- expect(@mods_rec.alternative_titles).to eq(['12'])
105
- end
106
- it "should not get an alternative title if type attribute is absent from titleInfo" do
107
- @mods_rec.from_str("<mods #{@ns_decl}><titleInfo><title>ta da!</title></titleInfo></mods>")
108
- expect(@mods_rec.alternative_titles).to eq([])
109
- end
110
- it "should not get an alternative title if type attribute from titleInfo is not 'alternative'" do
111
- @mods_rec.from_str("<mods #{@ns_decl}><titleInfo type='uniform'><title>ta da!</title></titleInfo></mods>")
112
- expect(@mods_rec.alternative_titles).to eq([])
113
- end
114
- # note that Mods::Record.alternative_title tests are in record_spec
115
- end
116
- end # WITH namespaces
117
-
118
- context "WITHOUT namespaces" do
119
-
120
- it "should recognize type attribute on titleInfo element" do
121
- Mods::TitleInfo::TYPES.each { |t|
122
- @mods_rec.from_str("<mods><titleInfo type='#{t}'>hi</titleInfo></mods>", false)
123
- expect(@mods_rec.title_info.type_at).to eq([t])
124
- }
125
- end
126
- it "should recognize subelements" do
127
- Mods::TitleInfo::CHILD_ELEMENTS.each { |e|
128
- @mods_rec.from_str("<mods><titleInfo><#{e}>oofda</#{e}></titleInfo></mods>", false)
129
- expect(@mods_rec.title_info.send(e).text).to eq('oofda')
130
- }
131
- end
132
-
133
- context "short_title" do
134
- it "should start with nonSort element" do
135
- @mods_rec.from_str("<mods><titleInfo><title>Jerk</title><nonSort>The</nonSort></titleInfo></mods>", false)
136
- expect(@mods_rec.title_info.short_title).to eq(["The Jerk"])
137
- end
138
- it "should not include subtitle" do
139
- @mods_rec.from_str("<mods><titleInfo><title>Jerk</title><subTitle>A Tale of Tourettes</subTitle><nonSort>The</nonSort></titleInfo></mods>", false)
140
- expect(@mods_rec.title_info.short_title).to eq(["The Jerk"])
141
- end
142
- it "Mods::Record.short_titles convenience method should return an Array (multiple titles are legal in Mods)" do
143
- @mods_rec.from_str("<mods><titleInfo><title>Jerk</title><nonSort>The</nonSort></titleInfo><titleInfo><title>Joke</title></titleInfo></mods>", false)
144
- expect(@mods_rec.short_titles).to eq(["The Jerk", "Joke"])
145
- end
146
- it "should not include alternative titles" do
147
- @mods_rec.from_str("<mods><titleInfo type='alternative'><title>ta da!</title></titleInfo></mods>", false)
148
- expect(@mods_rec.short_titles).not_to include("ta da!")
149
- @mods_rec.from_str("<mods><titleInfo type='alternative'><title>1</title></titleInfo><titleInfo><title>2</title></titleInfo></mods>", false)
150
- expect(@mods_rec.short_titles).to eq(['2'])
151
- end
152
- # note that Mods::Record.short_title tests are in record_spec
153
- end
154
-
155
- context "full_title" do
156
- it "should start with nonSort element" do
157
- @mods_rec.from_str("<mods><titleInfo><title>Jerk</title><nonSort>The</nonSort></titleInfo></mods>", false)
158
- expect(@mods_rec.title_info.full_title).to eq(["The Jerk"])
159
- end
160
- it "should include subtitle" do
161
- @mods_rec.from_str("<mods><titleInfo><title>Jerk</title><subTitle>A Tale of Tourettes</subTitle><nonSort>The</nonSort></titleInfo></mods>", false)
162
- expect(@mods_rec.title_info.full_title).to eq(["The Jerk A Tale of Tourettes"])
163
- end
164
- it "Mods::Record.full_titles convenience method should return an Array (multiple titles are legal in Mods)" do
165
- @mods_rec.from_str("<mods><titleInfo><title>Jerk</title><nonSort>The</nonSort></titleInfo><titleInfo><title>Joke</title></titleInfo></mods>", false)
166
- expect(@mods_rec.full_titles).to eq(["The Jerk", "Joke"])
167
- end
168
- # note that Mods::Record.full_title tests are in record_spec
169
- end
170
-
171
- context "sort_title" do
172
- it "should skip nonSort element" do
173
- @mods_rec.from_str("<mods><titleInfo><title>Jerk</title><nonSort>The</nonSort></titleInfo></mods>", false)
174
- expect(@mods_rec.title_info.sort_title).to eq(["Jerk"])
175
- end
176
- it "should contain title and subtitle" do
177
- @mods_rec.from_str("<mods><titleInfo><title>Jerk</title><subTitle>A Tale of Tourettes</subTitle><nonSort>The</nonSort></titleInfo></mods>", false)
178
- expect(@mods_rec.title_info.sort_title).to eq(["Jerk A Tale of Tourettes"])
179
- end
180
- it "should be an alternative title if there are no other choices" do
181
- @mods_rec.from_str("<mods><titleInfo type='alternative'><title>1</title></titleInfo></mods>", false)
182
- expect(@mods_rec.title_info.sort_title).to eq(['1'])
183
- end
184
- it "should not be an alternative title if there are other choices" do
185
- @mods_rec.from_str("<mods><titleInfo type='alternative'><title>1</title></titleInfo><titleInfo><title>2</title></titleInfo></mods>", false)
186
- expect(@mods_rec.title_info.sort_title).to eq(['2'])
187
- expect(@mods_rec.sort_title).to eq('2')
188
- end
189
- it "should have a configurable delimiter between title and subtitle" do
190
- m = Mods::Record.new(' : ')
191
- m.from_str("<mods><titleInfo><title>Jerk</title><subTitle>A Tale of Tourettes</subTitle><nonSort>The</nonSort></titleInfo></mods>", false)
192
- expect(m.title_info.sort_title).to eq(["Jerk : A Tale of Tourettes"])
193
- end
194
- context "Mods::Record.sort_title convenience method" do
195
- it "convenience method sort_title in Mods::Record should return a string" do
196
- @mods_rec.from_str("<mods><titleInfo><title>Jerk</title><subTitle>A Tale of Tourettes</subTitle><nonSort>The</nonSort></titleInfo></mods>", false)
197
- expect(@mods_rec.sort_title).to eq("Jerk A Tale of Tourettes")
198
- end
199
- end
200
- # note that Mods::Record.sort_title tests are in record_spec
201
- end
202
-
203
- context "alternative_title" do
204
- it "should get an alternative title, if it exists" do
205
- @mods_rec.from_str("<mods><titleInfo type='alternative'><title>ta da!</title></titleInfo></mods>", false)
206
- expect(@mods_rec.title_info.alternative_title).to eq(["ta da!"])
207
- end
208
- it "Mods::Record.alternative_titles convenience method for getting an Array of alternative titles when there are multiple elements" do
209
- @mods_rec.from_str("<mods><titleInfo type='alternative'><title>1</title></titleInfo><titleInfo type='alternative'><title>2</title></titleInfo></mods>", false)
210
- expect(@mods_rec.alternative_titles).to eq(['1', '2'])
211
- @mods_rec.from_str("<mods><titleInfo type='alternative'><title>1</title><title>2</title></titleInfo></mods>", false)
212
- expect(@mods_rec.alternative_titles).to eq(['12'])
213
- end
214
- it "should not get an alternative title if type attribute is absent from titleInfo" do
215
- @mods_rec.from_str("<mods><titleInfo><title>ta da!</title></titleInfo></mods>", false)
216
- expect(@mods_rec.alternative_titles).to eq([])
217
- end
218
- it "should not get an alternative title if type attribute from titleInfo is not 'alternative'" do
219
- @mods_rec.from_str("<mods><titleInfo type='uniform'><title>ta da!</title></titleInfo></mods>", false)
220
- expect(@mods_rec.alternative_titles).to eq([])
221
- end
222
- # note that Mods::Record.alternative_title tests are in record_spec
223
- end
224
- end # WITHOUT namespaces
225
-
226
- end
@@ -1,369 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "Mods Top Level Elements that do not have Child Elements" do
4
-
5
- before(:all) do
6
- @mods_rec = Mods::Record.new
7
- end
8
-
9
- it "should deal with camelcase vs. ruby underscore convention" do
10
- skip "need to implement ruby style version of (element/attribute) method names"
11
- end
12
-
13
- it "should get the text contents of any single complex top level element instance with no child elements" do
14
- skip "to be implemented"
15
- Mods::TOP_LEVEL_ELEMENTS_COMPLEX.each { |elname|
16
- @mods_rec.from_str("<mods><#{elname}>hi</#{elname}></mods>", false)
17
- expect(@mods_rec.send(elname.to_sym).map { |e| e.text }).to eq(["hi"])
18
- }
19
- end
20
-
21
- context "parsing without namespaces" do
22
-
23
- it "should get the text contents of any single simple (cannot have child elements) top level element" do
24
- Mods::TOP_LEVEL_ELEMENTS_SIMPLE.each { |elname|
25
- @mods_rec.from_str("<mods><#{elname}>hi</#{elname}></mods>", false)
26
- expect(@mods_rec.send(elname.to_sym).map { |e| e.text }).to eq(["hi"])
27
- }
28
- end
29
-
30
- it "should return an array of strings when there are multiple occurrences of simple top level elements" do
31
- expect(@mods_rec.from_str('<mods><note>hi</note><note>hello</note></mods>', false).note.map { |e| e.text }).to eq(["hi", "hello"])
32
- end
33
-
34
- context "<abstract> child element" do
35
- it ".abstract.displayLabel should be an accessor for displayLabel attribute on abstract element: <abstract displayLabel='foo'>" do
36
- @mods_rec.from_str('<mods><abstract displayLabel="Summary">blah blah blah</abstract></mods>', false)
37
- expect(@mods_rec.abstract.displayLabel).to eq(['Summary'])
38
- end
39
- it ".abstract.type_at should be an accessor for type attribute on abstract element: <abstract type='foo'>" do
40
- @mods_rec.from_str('<mods><abstract type="Scope and Contents note">blah blah blah</abstract></mods>', false)
41
- expect(@mods_rec.abstract.type_at).to eq(['Scope and Contents note'])
42
- end
43
- end
44
-
45
- context "<accessCondition> child element" do
46
- before(:all) do
47
- @acc_cond = @mods_rec.from_str('<mods><accessCondition displayLabel="meh" type="useAndReproduction">blah blah blah</accessCondition></mods>', false).accessCondition
48
- @acc_cond2 = @mods_rec.from_str('<mods><accessCondition type="useAndReproduction">All rights reserved.</accessCondition></mods>', false).accessCondition
49
- end
50
- it ".accessCondition.displayLabel should be an accessor for displayLabel attribute on accessCondition element: <accessCondition displayLabel='foo'>" do
51
- expect(@acc_cond.displayLabel).to eq(['meh'])
52
- end
53
- it ".accessCondition.type_at should be an accessor for type attribute on accessCondition element: <accessCondition type='foo'>" do
54
- [@acc_cond, @acc_cond2].each { |ac| expect(ac.type_at).to eq(['useAndReproduction']) }
55
- end
56
- end
57
-
58
- context "<classification> child element" do
59
- before(:all) do
60
- @class1 = @mods_rec.from_str('<mods><classification authority="ddc" edition="11">683</classification></mods>', false).classification
61
- @class2 = @mods_rec.from_str('<mods><classification authority="lcc">JK609.M2</classification></mods>', false).classification
62
- end
63
- it ".classification.authority should be an accessor for authority attribute on classification element: <classification authority='foo'>" do
64
- expect(@class1.authority).to eq(['ddc'])
65
- expect(@class2.authority).to eq(['lcc'])
66
- end
67
- it ".classification.edition should be an accessor for edition attribute on classification element: <classification edition='foo'>" do
68
- expect(@class1.edition).to eq(['11'])
69
- end
70
- it "should recognize all authority attributes" do
71
- Mods::AUTHORITY_ATTRIBS.each { |a|
72
- @mods_rec.from_str("<mods><classification #{a}='attr_val'>zzz</classification></mods>", false)
73
- expect(@mods_rec.classification.send(a.to_sym)).to eq(['attr_val'])
74
- }
75
- end
76
- end
77
-
78
- context "<extension> child element" do
79
- before(:all) do
80
- @ext = @mods_rec.from_str('<mods><extension xmlns:dcterms="http://purl.org/dc/terms/" >
81
- <dcterms:modified>2003-03-24</dcterms:modified>
82
- </extension></mods>', false).extension
83
- end
84
- it ".extension.displayLabel should be an accessor for displayLabel attribute on extension element: <extension displayLabel='foo'>" do
85
- @mods_rec.from_str('<mods><extension displayLabel="something">blah blah blah</extension></mods>', false)
86
- expect(@mods_rec.extension.displayLabel).to eq(['something'])
87
- end
88
- end
89
-
90
- context "<genre> child element" do
91
- it ".genre.displayLabel should be an accessor for displayLabel attribute on genre element: <genre displayLabel='foo'>" do
92
- @mods_rec.from_str('<mods><genre displayLabel="something">blah blah blah</genre></mods>', false)
93
- expect(@mods_rec.genre.displayLabel).to eq(['something'])
94
- end
95
- it ".genre.type_at should be an accessor for type attribute on genre element: <genre type='foo'>" do
96
- @mods_rec.from_str('<mods><genre type="maybe">blah blah blah</genre></mods>', false)
97
- expect(@mods_rec.genre.type_at).to eq(['maybe'])
98
- end
99
- it ".genre.usage should be an accessor for usage attribute on genre element: <genre usage='foo'>" do
100
- @mods_rec.from_str('<mods><genre usage="fer sure">blah blah blah</genre></mods>', false)
101
- expect(@mods_rec.genre.usage).to eq(['fer sure'])
102
- end
103
- it "should recognize all authority attributes" do
104
- Mods::AUTHORITY_ATTRIBS.each { |a|
105
- @mods_rec.from_str("<mods><genre #{a}='attr_val'>zzz</genre></mods>", false)
106
- expect(@mods_rec.genre.send(a.to_sym)).to eq(['attr_val'])
107
- }
108
- end
109
- end
110
-
111
- context "<identifier> child element" do
112
- before(:all) do
113
- @id = @mods_rec.from_str('<mods><identifier displayLabel="book_number" type="local">70</identifier></mods>', false).identifier
114
- end
115
- it ".identifier.displayLabel should be an accessor for displayLabel attribute on identifier element: <identifier displayLabel='foo'>" do
116
- expect(@id.displayLabel).to eq(['book_number'])
117
- end
118
- it ".identifier.invalid should be an accessor for invalid attribute on identifier element: <identifier invalid='foo'>" do
119
- @mods_rec.from_str('<mods> <identifier type="isbn" invalid="yes">0877780116</identifier></mods>', false)
120
- expect(@mods_rec.identifier.invalid).to eq(['yes'])
121
- end
122
- it ".identifier.type_at should be an accessor for type attribute on identifier element: <identifier type='foo'>" do
123
- expect(@id.type_at).to eq(['local'])
124
- end
125
- end
126
-
127
- context "<note> child element" do
128
- it ".note.displayLabel should be an accessor for displayLabel attribute on note element: <note displayLabel='foo'>" do
129
- @mods_rec.from_str('<mods><note displayLabel="state_note">blah</note></mods>', false)
130
- expect(@mods_rec.note.displayLabel).to eq(['state_note'])
131
- end
132
- it ".note.id_at should be an accessor for ID attribute on note element: <note ID='foo'>" do
133
- @mods_rec.from_str('<mods><note ID="foo">blah blah blah</note></mods>', false)
134
- expect(@mods_rec.note.id_at).to eq(['foo'])
135
- end
136
- it ".note.type_at should be an accessor for type attribute on note element: <note type='foo'>" do
137
- @mods_rec.from_str('<mods><note type="content">blah</note></mods>', false)
138
- expect(@mods_rec.note.type_at).to eq(['content'])
139
- end
140
- end
141
-
142
- context "<tableOfContents> child element" do
143
- it ".tableOfContents.displayLabel should be an accessor for displayLabel attribute on tableOfContents element: <tableOfContents displayLabel='foo'>" do
144
- @mods_rec.from_str('<mods><tableOfContents displayLabel="Chapters included in book">blah blah</tableOfContents></mods>', false)
145
- expect(@mods_rec.tableOfContents.displayLabel).to eq(['Chapters included in book'])
146
- end
147
- it ".tableOfContents.shareable should be an accessor for shareable attribute on tableOfContents element: <tableOfContents shareable='foo'>" do
148
- @mods_rec.from_str('<mods><tableOfContents shareable="no">blah blah blah</tableOfContents></mods>', false)
149
- expect(@mods_rec.tableOfContents.shareable).to eq(['no'])
150
- end
151
- it ".tableOfContents.type_at should be an accessor for type attribute on tableOfContents element: <tableOfContents type='foo'>" do
152
- @mods_rec.from_str('<mods><tableOfContents type="partial contents">blah blah</tableOfContents></mods>', false)
153
- expect(@mods_rec.tableOfContents.type_at).to eq(['partial contents'])
154
- end
155
- end
156
-
157
- context "<targetAudience> child element" do
158
- it ".targetAudience.displayLabel should be an accessor for displayLabel attribute on targetAudience element: <targetAudience displayLabel='foo'>" do
159
- @mods_rec.from_str('<mods><targetAudience displayLabel="ta da">blah blah</targetAudience></mods>', false)
160
- expect(@mods_rec.targetAudience.displayLabel).to eq(['ta da'])
161
- end
162
- it "should recognize all authority attributes" do
163
- Mods::AUTHORITY_ATTRIBS.each { |a|
164
- @mods_rec.from_str("<mods><targetAudience #{a}='attr_val'>zzz</targetAudience></mods>", false)
165
- expect(@mods_rec.targetAudience.send(a.to_sym)).to eq(['attr_val'])
166
- }
167
- end
168
- end
169
-
170
- context "<typeOfResource> child element" do
171
- before(:all) do
172
- '<typeOfResource manuscript="yes">mixed material</typeOfResource>'
173
- end
174
- it ".typeOfResource.collection should be an accessor for collection attribute on typeOfResource element: <typeOfResource collection='foo'>" do
175
- @mods_rec.from_str('<mods><typeOfResource collection="yes">blah blah blah</typeOfResource></mods>', false)
176
- expect(@mods_rec.typeOfResource.collection).to eq(['yes'])
177
- end
178
- it ".typeOfResource.displayLabel should be an accessor for displayLabel attribute on typeOfResource element: <typeOfResource displayLabel='foo'>" do
179
- @mods_rec.from_str('<mods><typeOfResource displayLabel="Summary">blah blah blah</typeOfResource></mods>', false)
180
- expect(@mods_rec.typeOfResource.displayLabel).to eq(['Summary'])
181
- end
182
- it ".typeOfResource.manuscript should be an accessor for manuscript attribute on typeOfResource element: <typeOfResource manuscript='foo'>" do
183
- @mods_rec.from_str('<mods><typeOfResource manuscript="yes">blah blah blah</typeOfResource></mods>', false)
184
- expect(@mods_rec.typeOfResource.manuscript).to eq(['yes'])
185
- end
186
- it ".typeOfResource.usage should be an accessor for usage attribute on typeOfResource element: <typeOfResource usage='foo'>" do
187
- @mods_rec.from_str('<mods><typeOfResource usage="fer sure">blah blah blah</typeOfResource></mods>', false)
188
- expect(@mods_rec.typeOfResource.usage).to eq(['fer sure'])
189
- end
190
- end
191
-
192
- end # context without namespaces
193
-
194
- context "parsing with namespaces" do
195
-
196
- before(:all) do
197
- @mods_el_w_ns = '<mods xmlns="http://www.loc.gov/mods/v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-2.xsd">'
198
- end
199
-
200
- it "should get the text contents of any single simple (cannot have child elements) top level element" do
201
- Mods::TOP_LEVEL_ELEMENTS_SIMPLE.each { |elname|
202
- @mods_rec.from_str(@mods_el_w_ns + "<#{elname}>hi</#{elname}></mods>")
203
- expect(@mods_rec.send(elname.to_sym).map { |e| e.text }).to eq(["hi"])
204
- }
205
- end
206
-
207
- it "should return an array of strings when there are multiple occurrences of simple top level elements" do
208
- expect(@mods_rec.from_str(@mods_el_w_ns + '<note>hi</note><note>hello</note></mods>').note.map { |e| e.text }).to eq(["hi", "hello"])
209
- end
210
-
211
- context "<abstract> child element" do
212
- it ".abstract.displayLabel should be an accessor for displayLabel attribute on abstract element: <abstract displayLabel='foo'>" do
213
- @mods_rec.from_str(@mods_el_w_ns + '<abstract displayLabel="Summary">blah blah blah</abstract></mods>')
214
- expect(@mods_rec.abstract.displayLabel).to eq(['Summary'])
215
- end
216
- it ".abstract.type_at should be an accessor for type attribute on abstract element: <abstract type='foo'>" do
217
- @mods_rec.from_str(@mods_el_w_ns + '<abstract type="Scope and Contents note">blah blah blah</abstract></mods>')
218
- expect(@mods_rec.abstract.type_at).to eq(['Scope and Contents note'])
219
- end
220
- end
221
-
222
- context "<accessCondition> child element" do
223
- before(:all) do
224
- @acc_cond = @mods_rec.from_str(@mods_el_w_ns + '<accessCondition displayLabel="meh" type="useAndReproduction">blah blah blah</accessCondition></mods>').accessCondition
225
- @acc_cond2 = @mods_rec.from_str(@mods_el_w_ns + '<accessCondition type="useAndReproduction">All rights reserved.</accessCondition></mods>').accessCondition
226
- end
227
- it ".accessCondition.displayLabel should be an accessor for displayLabel attribute on accessCondition element: <accessCondition displayLabel='foo'>" do
228
- expect(@acc_cond.displayLabel).to eq(['meh'])
229
- end
230
- it ".accessCondition.type_at should be an accessor for type attribute on accessCondition element: <accessCondition type='foo'>" do
231
- [@acc_cond, @acc_cond2].each { |ac| expect(ac.type_at).to eq(['useAndReproduction']) }
232
- end
233
- end
234
-
235
- context "<classification> child element" do
236
- before(:all) do
237
- @class1 = @mods_rec.from_str(@mods_el_w_ns + '<classification authority="ddc" edition="11">683</classification></mods>').classification
238
- @class2 = @mods_rec.from_str(@mods_el_w_ns + '<classification authority="lcc">JK609.M2</classification></mods>').classification
239
- end
240
- it ".classification.authority should be an accessor for authority attribute on classification element: <classification authority='foo'>" do
241
- expect(@class1.authority).to eq(['ddc'])
242
- expect(@class2.authority).to eq(['lcc'])
243
- end
244
- it ".classification.edition should be an accessor for edition attribute on classification element: <classification edition='foo'>" do
245
- expect(@class1.edition).to eq(['11'])
246
- end
247
- it "should recognize all authority attributes" do
248
- Mods::AUTHORITY_ATTRIBS.each { |a|
249
- @mods_rec.from_str(@mods_el_w_ns + "<classification #{a}='attr_val'>zzz</classification></mods>")
250
- expect(@mods_rec.classification.send(a.to_sym)).to eq(['attr_val'])
251
- }
252
- end
253
- end
254
-
255
- context "<extension> child element" do
256
- before(:all) do
257
- @ext = @mods_rec.from_str(@mods_el_w_ns + '<extension xmlns:dcterms="http://purl.org/dc/terms/" >
258
- <dcterms:modified>2003-03-24</dcterms:modified>
259
- </extension></mods>').extension
260
- end
261
- it ".extension.displayLabel should be an accessor for displayLabel attribute on extension element: <extension displayLabel='foo'>" do
262
- @mods_rec.from_str(@mods_el_w_ns + '<extension displayLabel="something">blah blah blah</extension></mods>')
263
- expect(@mods_rec.extension.displayLabel).to eq(['something'])
264
- end
265
- end
266
-
267
- context "<genre> child element" do
268
- it ".genre.displayLabel should be an accessor for displayLabel attribute on genre element: <genre displayLabel='foo'>" do
269
- @mods_rec.from_str(@mods_el_w_ns + '<genre displayLabel="something">blah blah blah</genre></mods>')
270
- expect(@mods_rec.genre.displayLabel).to eq(['something'])
271
- end
272
- it ".genre.type_at should be an accessor for type attribute on genre element: <genre type='foo'>" do
273
- @mods_rec.from_str(@mods_el_w_ns + '<genre type="maybe">blah blah blah</genre></mods>')
274
- expect(@mods_rec.genre.type_at).to eq(['maybe'])
275
- end
276
- it ".genre.usage should be an accessor for usage attribute on genre element: <genre usage='foo'>" do
277
- @mods_rec.from_str(@mods_el_w_ns + '<genre usage="fer sure">blah blah blah</genre></mods>')
278
- expect(@mods_rec.genre.usage).to eq(['fer sure'])
279
- end
280
- it "should recognize all authority attributes" do
281
- Mods::AUTHORITY_ATTRIBS.each { |a|
282
- @mods_rec.from_str(@mods_el_w_ns + "<genre #{a}='attr_val'>zzz</genre></mods>")
283
- expect(@mods_rec.genre.send(a.to_sym)).to eq(['attr_val'])
284
- }
285
- end
286
- end
287
-
288
- context "<identifier> child element" do
289
- before(:all) do
290
- @id = @mods_rec.from_str(@mods_el_w_ns + '<identifier displayLabel="book_number" type="local">70</identifier></mods>').identifier
291
- end
292
- it ".identifier.displayLabel should be an accessor for displayLabel attribute on identifier element: <identifier displayLabel='foo'>" do
293
- expect(@id.displayLabel).to eq(['book_number'])
294
- end
295
- it ".identifier.invalid should be an accessor for invalid attribute on identifier element: <identifier invalid='foo'>" do
296
- @mods_rec.from_str(@mods_el_w_ns + '<identifier type="isbn" invalid="yes">0877780116</identifier></mods>')
297
- expect(@mods_rec.identifier.invalid).to eq(['yes'])
298
- end
299
- it ".identifier.type_at should be an accessor for type attribute on identifier element: <identifier type='foo'>" do
300
- expect(@id.type_at).to eq(['local'])
301
- end
302
- end
303
-
304
- context "<note> child element" do
305
- it ".note.displayLabel should be an accessor for displayLabel attribute on note element: <note displayLabel='foo'>" do
306
- @mods_rec.from_str(@mods_el_w_ns + '<note displayLabel="state_note">blah</note></mods>')
307
- expect(@mods_rec.note.displayLabel).to eq(['state_note'])
308
- end
309
- it ".note.id_at should be an accessor for ID attribute on note element: <note ID='foo'>" do
310
- @mods_rec.from_str(@mods_el_w_ns + '<note ID="foo">blah blah blah</note></mods>')
311
- expect(@mods_rec.note.id_at).to eq(['foo'])
312
- end
313
- it ".note.type_at should be an accessor for type attribute on note element: <note type='foo'>" do
314
- @mods_rec.from_str(@mods_el_w_ns + '<note type="content">blah</note></mods>')
315
- expect(@mods_rec.note.type_at).to eq(['content'])
316
- end
317
- end
318
-
319
- context "<tableOfContents> child element" do
320
- it ".tableOfContents.displayLabel should be an accessor for displayLabel attribute on tableOfContents element: <tableOfContents displayLabel='foo'>" do
321
- @mods_rec.from_str(@mods_el_w_ns + '<tableOfContents displayLabel="Chapters included in book">blah blah</tableOfContents></mods>')
322
- expect(@mods_rec.tableOfContents.displayLabel).to eq(['Chapters included in book'])
323
- end
324
- it ".tableOfContents.shareable should be an accessor for shareable attribute on tableOfContents element: <tableOfContents shareable='foo'>" do
325
- @mods_rec.from_str(@mods_el_w_ns + '<tableOfContents shareable="no">blah blah blah</tableOfContents></mods>')
326
- expect(@mods_rec.tableOfContents.shareable).to eq(['no'])
327
- end
328
- it ".tableOfContents.type_at should be an accessor for type attribute on tableOfContents element: <tableOfContents type='foo'>" do
329
- @mods_rec.from_str(@mods_el_w_ns + '<tableOfContents type="partial contents">blah blah</tableOfContents></mods>')
330
- expect(@mods_rec.tableOfContents.type_at).to eq(['partial contents'])
331
- end
332
- end
333
-
334
- context "<targetAudience> child element" do
335
- it ".targetAudience.displayLabel should be an accessor for displayLabel attribute on targetAudience element: <targetAudience displayLabel='foo'>" do
336
- @mods_rec.from_str(@mods_el_w_ns + '<targetAudience displayLabel="ta da">blah blah</targetAudience></mods>')
337
- expect(@mods_rec.targetAudience.displayLabel).to eq(['ta da'])
338
- end
339
- it "should recognize all authority attributes" do
340
- Mods::AUTHORITY_ATTRIBS.each { |a|
341
- @mods_rec.from_str(@mods_el_w_ns + "<targetAudience #{a}='attr_val'>zzz</targetAudience></mods>")
342
- expect(@mods_rec.targetAudience.send(a.to_sym)).to eq(['attr_val'])
343
- }
344
- end
345
- end
346
-
347
- context "<typeOfResource> child element" do
348
- it ".typeOfResource.collection should be an accessor for collection attribute on typeOfResource element: <typeOfResource collection='foo'>" do
349
- @mods_rec.from_str(@mods_el_w_ns + '<typeOfResource collection="yes">blah blah blah</typeOfResource></mods>')
350
- expect(@mods_rec.typeOfResource.collection).to eq(['yes'])
351
- end
352
- it ".typeOfResource.displayLabel should be an accessor for displayLabel attribute on typeOfResource element: <typeOfResource displayLabel='foo'>" do
353
- @mods_rec.from_str(@mods_el_w_ns + '<typeOfResource displayLabel="Summary">blah blah blah</typeOfResource></mods>')
354
- expect(@mods_rec.typeOfResource.displayLabel).to eq(['Summary'])
355
- end
356
- it ".typeOfResource.manuscript should be an accessor for manuscript attribute on typeOfResource element: <typeOfResource manuscript='foo'>" do
357
- @mods_rec.from_str(@mods_el_w_ns + '<typeOfResource manuscript="yes">blah blah blah</typeOfResource></mods>')
358
- expect(@mods_rec.typeOfResource.manuscript).to eq(['yes'])
359
- end
360
- it ".typeOfResource.usage should be an accessor for usage attribute on typeOfResource element: <typeOfResource usage='foo'>" do
361
- @mods_rec.from_str(@mods_el_w_ns + '<typeOfResource usage="fer sure">blah blah blah</typeOfResource></mods>')
362
- expect(@mods_rec.typeOfResource.usage).to eq(['fer sure'])
363
- end
364
- end
365
-
366
- end # parsing with namespaces
367
-
368
-
369
- end