mods 0.0.8 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +1 -0
- data/lib/mods/reader.rb +8 -0
- data/lib/mods/record.rb +13 -2
- data/lib/mods/version.rb +1 -1
- data/spec/name_spec.rb +1 -1
- data/spec/origin_info_spec.rb +9 -9
- data/spec/reader_spec.rb +42 -0
- data/spec/record_spec.rb +46 -0
- data/spec/subject_spec.rb +2 -2
- metadata +6 -4
data/README.rdoc
CHANGED
@@ -37,6 +37,7 @@ TODO: Write usage instructions here
|
|
37
37
|
|
38
38
|
== Releases
|
39
39
|
|
40
|
+
0.0.9 implement from_nk_node as way to load record object
|
40
41
|
0.0.8 implement relatedItem and attributes on all simple top level elements
|
41
42
|
0.0.7 implement part
|
42
43
|
0.0.6 implement recordInfo, fix to work under jruby
|
data/lib/mods/reader.rb
CHANGED
@@ -29,6 +29,14 @@ module Mods
|
|
29
29
|
@mods_ng_xml
|
30
30
|
end
|
31
31
|
|
32
|
+
# @param node (Nokogiri::XML::Node) - Nokogiri::XML::Node that is the top level element of a mods record
|
33
|
+
# @return a Nokogiri::XML::Document object
|
34
|
+
def from_nk_node(node)
|
35
|
+
@mods_ng_xml = Nokogiri::XML(node.to_s)
|
36
|
+
normalize_mods
|
37
|
+
@mods_ng_xml
|
38
|
+
end
|
39
|
+
|
32
40
|
# Whatever we get, normalize it into a Nokogiri::XML::Document,
|
33
41
|
# strip any elements enclosing the mods record
|
34
42
|
def normalize_mods
|
data/lib/mods/record.rb
CHANGED
@@ -45,6 +45,18 @@ module Mods
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
+
# convenience method to call Mods::Reader.new.from_nk_node and to nom
|
49
|
+
# @param ns_aware true if the XML parsing should be strict about using namespaces. Default is false
|
50
|
+
# @param node (Nokogiri::XML::Node) - Nokogiri::XML::Node that is the top level element of a mods record
|
51
|
+
def from_nk_node(node, ns_aware = false)
|
52
|
+
@mods_ng_xml = Mods::Reader.new(ns_aware).from_nk_node(node)
|
53
|
+
if ns_aware
|
54
|
+
set_terminology_ns(@mods_ng_xml)
|
55
|
+
else
|
56
|
+
set_terminology_no_ns(@mods_ng_xml)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
48
60
|
# @return Array of Strings, each containing the text contents of <mods><titleInfo> <nonSort> + ' ' + <title> elements
|
49
61
|
# but not including any titleInfo elements with type="alternative"
|
50
62
|
def short_titles
|
@@ -66,7 +78,6 @@ module Mods
|
|
66
78
|
@mods_ng_xml.title_info.sort_title.find { |n| !n.nil? }
|
67
79
|
end
|
68
80
|
|
69
|
-
|
70
81
|
# use the displayForm of a personal name if present
|
71
82
|
# if no displayForm, try to make a string from family name and given name "family_name, given_name"
|
72
83
|
# otherwise, return all nameParts concatenated together
|
@@ -110,7 +121,7 @@ module Mods
|
|
110
121
|
result << ISO_639.find(v.strip).english_name
|
111
122
|
end
|
112
123
|
rescue => e
|
113
|
-
p "Couldn't find english name for #{
|
124
|
+
p "Couldn't find english name for #{ct.text}"
|
114
125
|
result << ct.text
|
115
126
|
end
|
116
127
|
else
|
data/lib/mods/version.rb
CHANGED
data/spec/name_spec.rb
CHANGED
data/spec/origin_info_spec.rb
CHANGED
@@ -160,12 +160,12 @@ describe "Mods <originInfo> Element" do
|
|
160
160
|
|
161
161
|
end
|
162
162
|
|
163
|
-
context "basic
|
163
|
+
context "basic <originInfo> terminology pieces" do
|
164
164
|
before(:all) do
|
165
165
|
@mods_rec.from_str(@form_and_extent)
|
166
166
|
end
|
167
167
|
|
168
|
-
context "place child element" do
|
168
|
+
context "<place> child element" do
|
169
169
|
before(:all) do
|
170
170
|
@place_term_text = '<mods><originInfo><place><placeTerm type="text">Iran</placeTerm></place></originInfo></mods>'
|
171
171
|
@place_term_plain_mult = '<mods><originInfo>
|
@@ -177,7 +177,7 @@ describe "Mods <originInfo> Element" do
|
|
177
177
|
@yuck3 = '<mods><originInfo><place><placeTerm type="text">[s.l. : s.n.]</placeTerm></place></originInfo></mods>'
|
178
178
|
@yuck4 = '<mods><originInfo><place><placeTerm type="text">[London]</placeTerm></place></originInfo></mods>'
|
179
179
|
end
|
180
|
-
context "placeTerm child element" do
|
180
|
+
context "<placeTerm> child element" do
|
181
181
|
it "should get element values" do
|
182
182
|
vals = @mods_rec.from_str(@place_term_plain_mult).origin_info.place.placeTerm.map { |e| e.text}
|
183
183
|
vals.size.should == 2
|
@@ -202,7 +202,7 @@ describe "Mods <originInfo> Element" do
|
|
202
202
|
end # placeTerm
|
203
203
|
end # place
|
204
204
|
|
205
|
-
context "publisher child element" do
|
205
|
+
context "<publisher> child element" do
|
206
206
|
before(:all) do
|
207
207
|
@ex = '<mods><originInfo><publisher>Olney</publisher></origin_info></mods>'
|
208
208
|
@yuck1 = '<mods><originInfo><publisher>[s.n.]</publisher></originInfo></mods>'
|
@@ -220,7 +220,7 @@ describe "Mods <originInfo> Element" do
|
|
220
220
|
end
|
221
221
|
end
|
222
222
|
|
223
|
-
context "
|
223
|
+
context "<xxxDate> child elements" do
|
224
224
|
it "should recognize each element" do
|
225
225
|
Mods::ORIGIN_INFO_DATE_ELEMENTS.each { |elname|
|
226
226
|
@mods_rec.from_str("<mods><originInfo><#{elname}>date</#{elname}></originInfo></mods>")
|
@@ -274,14 +274,14 @@ describe "Mods <originInfo> Element" do
|
|
274
274
|
it "should know the only valid values for qualifier attribute: approximate, inferred, questionable" do
|
275
275
|
pending "to be implemented"
|
276
276
|
end
|
277
|
-
end
|
277
|
+
end # <xxxDate> child elements
|
278
278
|
|
279
|
-
it "edition child element" do
|
279
|
+
it "<edition> child element" do
|
280
280
|
xml = '<mods><originInfo><edition>7th ed.</edition></originInfo></mods>'
|
281
281
|
@mods_rec.from_str(xml).origin_info.edition.map { |n| n.text }.should == ['7th ed.']
|
282
282
|
end
|
283
283
|
|
284
|
-
context "issuance child element" do
|
284
|
+
context "<issuance> child element" do
|
285
285
|
before(:all) do
|
286
286
|
@ex = '<mods><originInfo><issuance>monographic</issuance></originInfo></mods>'
|
287
287
|
end
|
@@ -293,7 +293,7 @@ describe "Mods <originInfo> Element" do
|
|
293
293
|
end
|
294
294
|
end
|
295
295
|
|
296
|
-
context "frequency child element" do
|
296
|
+
context "<frequency> child element" do
|
297
297
|
before(:all) do
|
298
298
|
xml = '<mods><originInfo><frequency authority="marcfrequency">Annual</frequency></originInfo></mods>'
|
299
299
|
@origin_info = @mods_rec.from_str(xml).origin_info
|
data/spec/reader_spec.rb
CHANGED
@@ -20,6 +20,48 @@ describe "Mods::Reader" do
|
|
20
20
|
it "from_url should turn the contents at the url into a Nokogiri::XML::Document object" do
|
21
21
|
@from_url.class.should == Nokogiri::XML::Document
|
22
22
|
end
|
23
|
+
|
24
|
+
context "from_nk_node" do
|
25
|
+
before(:all) do
|
26
|
+
oai_resp = '<?xml version="1.0" encoding="UTF-8"?>
|
27
|
+
<OAI-PMH xmlns="http://www.openarchives.org/OAI/2.0/">
|
28
|
+
<responseDate>2012-11-13T22:11:35Z</responseDate>
|
29
|
+
<request>http://sul-lyberservices-prod.stanford.edu/sw-oai-provider/oai</request>
|
30
|
+
<GetRecord>
|
31
|
+
<record>
|
32
|
+
<header>
|
33
|
+
<identifier>oai:searchworks.stanford.edu/druid:mm848sz7984</identifier>
|
34
|
+
<datestamp>2012-10-28T01:06:31Z</datestamp>
|
35
|
+
</header>
|
36
|
+
<metadata>
|
37
|
+
<ns3:mods xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns3="http://www.loc.gov/mods/v3" xsi:schemaLocation="http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-2.xsd">
|
38
|
+
<ns3:titleInfo>
|
39
|
+
<ns3:title>boo</ns3:title>
|
40
|
+
</ns3:titleInfo>
|
41
|
+
</ns3:mods>
|
42
|
+
</metadata>
|
43
|
+
</record>
|
44
|
+
</GetRecord>
|
45
|
+
</OAI-PMH>'
|
46
|
+
ng_xml = Nokogiri::XML(oai_resp)
|
47
|
+
@mods_node = ng_xml.xpath('//mods:mods', @ns_hash).first
|
48
|
+
@r = Mods::Reader.new
|
49
|
+
@mods_ng_doc = @r.from_nk_node(@mods_node)
|
50
|
+
end
|
51
|
+
it "should turn the Nokogiri::XML::Node into a Nokogiri::XML::Document object" do
|
52
|
+
@mods_ng_doc.should be_kind_of(Nokogiri::XML::Document)
|
53
|
+
end
|
54
|
+
it "should not care about namespace by default" do
|
55
|
+
@mods_ng_doc.xpath('/mods/titleInfo/title').text.should == "boo"
|
56
|
+
end
|
57
|
+
it "should be able to care about namespaces" do
|
58
|
+
@r.namespace_aware = true
|
59
|
+
@mods_ng_doc = @r.from_nk_node(@mods_node)
|
60
|
+
@mods_ng_doc.xpath('/mods:mods/mods:titleInfo/mods:title', @ns_hash).text.should == "boo"
|
61
|
+
@r.namespace_aware = false
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
23
65
|
|
24
66
|
context "namespace awareness" do
|
25
67
|
it "should not care about namespace by default" do
|
data/spec/record_spec.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Mods::Record" do
|
4
|
+
before(:all) do
|
5
|
+
@ns_hash = {'mods' => Mods::MODS_NS}
|
6
|
+
end
|
7
|
+
|
8
|
+
context "from_str" do
|
9
|
+
it "should be able to find element using NOM terminology" do
|
10
|
+
mods_ng_doc = Mods::Record.new.from_str('<mods><note>hi</note></mods>')
|
11
|
+
mods_ng_doc.note.map { |e| e.text } == "hi"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context "from_nk_node" do
|
16
|
+
before(:all) do
|
17
|
+
oai_resp = '<?xml version="1.0" encoding="UTF-8"?>
|
18
|
+
<OAI-PMH xmlns="http://www.openarchives.org/OAI/2.0/">
|
19
|
+
<responseDate>2012-11-13T22:11:35Z</responseDate>
|
20
|
+
<request>http://sul-lyberservices-prod.stanford.edu/sw-oai-provider/oai</request>
|
21
|
+
<GetRecord>
|
22
|
+
<record>
|
23
|
+
<header>
|
24
|
+
<identifier>oai:searchworks.stanford.edu/druid:mm848sz7984</identifier>
|
25
|
+
<datestamp>2012-10-28T01:06:31Z</datestamp>
|
26
|
+
</header>
|
27
|
+
<metadata>
|
28
|
+
<ns3:mods xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns3="http://www.loc.gov/mods/v3" xsi:schemaLocation="http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-2.xsd">
|
29
|
+
<ns3:titleInfo>
|
30
|
+
<ns3:title>boo</ns3:title>
|
31
|
+
</ns3:titleInfo>
|
32
|
+
</ns3:mods>
|
33
|
+
</metadata>
|
34
|
+
</record>
|
35
|
+
</GetRecord>
|
36
|
+
</OAI-PMH>'
|
37
|
+
ng_xml = Nokogiri::XML(oai_resp)
|
38
|
+
@mods_node = ng_xml.xpath('//mods:mods', @ns_hash).first
|
39
|
+
end
|
40
|
+
it "should be able to find element using NOM terminology" do
|
41
|
+
mods_ng_doc = Mods::Record.new.from_nk_node(@mods_node)
|
42
|
+
mods_ng_doc.title_info.title.map { |e| e.text } == "boo"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
data/spec/subject_spec.rb
CHANGED
@@ -104,10 +104,10 @@ describe "Mods <subject> Element" do
|
|
104
104
|
@mult_pers_name_sub.personal_name.date.map { |e| e.text }.should include("1818-1878")
|
105
105
|
end
|
106
106
|
it "should do the appropriate thing with the role for the value of a name" do
|
107
|
-
pending "to be implemented"
|
107
|
+
pending "name objects to be implemented"
|
108
108
|
end
|
109
109
|
it "should do the appropriate thing with the date for the value of a name" do
|
110
|
-
pending "to be implemented"
|
110
|
+
pending "name objects to be implemented"
|
111
111
|
end
|
112
112
|
end
|
113
113
|
|
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.9
|
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-11-
|
13
|
+
date: 2012-11-13 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: nokogiri
|
@@ -194,6 +194,7 @@ files:
|
|
194
194
|
- spec/physical_description_spec.rb
|
195
195
|
- spec/reader_spec.rb
|
196
196
|
- spec/record_info_spec.rb
|
197
|
+
- spec/record_spec.rb
|
197
198
|
- spec/related_item_spec.rb
|
198
199
|
- spec/spec_helper.rb
|
199
200
|
- spec/subject_spec.rb
|
@@ -213,7 +214,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
213
214
|
version: '0'
|
214
215
|
segments:
|
215
216
|
- 0
|
216
|
-
hash: -
|
217
|
+
hash: -681303896929700435
|
217
218
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
218
219
|
none: false
|
219
220
|
requirements:
|
@@ -222,7 +223,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
222
223
|
version: '0'
|
223
224
|
segments:
|
224
225
|
- 0
|
225
|
-
hash: -
|
226
|
+
hash: -681303896929700435
|
226
227
|
requirements: []
|
227
228
|
rubyforge_project:
|
228
229
|
rubygems_version: 1.8.24
|
@@ -238,6 +239,7 @@ test_files:
|
|
238
239
|
- spec/physical_description_spec.rb
|
239
240
|
- spec/reader_spec.rb
|
240
241
|
- spec/record_info_spec.rb
|
242
|
+
- spec/record_spec.rb
|
241
243
|
- spec/related_item_spec.rb
|
242
244
|
- spec/spec_helper.rb
|
243
245
|
- spec/subject_spec.rb
|