mods 0.0.14 → 0.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +1 -1
- data/lib/mods/nom_terminology.rb +445 -8
- data/lib/mods/reader.rb +3 -3
- data/lib/mods/record.rb +6 -7
- data/lib/mods/version.rb +1 -1
- data/spec/language_spec.rb +100 -73
- data/spec/location_spec.rb +269 -119
- data/spec/name_spec.rb +223 -197
- data/spec/origin_info_spec.rb +315 -190
- data/spec/part_spec.rb +411 -176
- data/spec/physical_description_spec.rb +120 -55
- data/spec/reader_spec.rb +76 -61
- data/spec/record_info_spec.rb +448 -206
- data/spec/record_spec.rb +192 -7
- data/spec/related_item_spec.rb +275 -124
- data/spec/subject_spec.rb +666 -339
- data/spec/title_spec.rb +204 -89
- data/spec/top_level_elmnts_simple_spec.rb +324 -145
- metadata +79 -98
data/lib/mods/reader.rb
CHANGED
@@ -3,13 +3,13 @@
|
|
3
3
|
module Mods
|
4
4
|
class Reader
|
5
5
|
|
6
|
-
DEFAULT_NS_AWARE =
|
6
|
+
DEFAULT_NS_AWARE = true
|
7
7
|
|
8
8
|
# true if the XML parsing should be strict about using namespaces.
|
9
9
|
attr_accessor :namespace_aware
|
10
10
|
attr_reader :mods_ng_xml
|
11
11
|
|
12
|
-
# @param ns_aware true if the XML parsing should be strict about using namespaces. Default is
|
12
|
+
# @param ns_aware true if the XML parsing should be strict about using namespaces. Default is true
|
13
13
|
def initialize(ns_aware = DEFAULT_NS_AWARE)
|
14
14
|
@namespace_aware = ns_aware
|
15
15
|
end
|
@@ -34,7 +34,7 @@ module Mods
|
|
34
34
|
# @param node (Nokogiri::XML::Node) - Nokogiri::XML::Node that is the top level element of a mods record
|
35
35
|
# @return Nokogiri::XML::Document
|
36
36
|
def from_nk_node(node)
|
37
|
-
@mods_ng_xml = Nokogiri::XML(node.to_s)
|
37
|
+
@mods_ng_xml = Nokogiri::XML(node.to_s, nil, node.document.encoding)
|
38
38
|
normalize_mods
|
39
39
|
@mods_ng_xml
|
40
40
|
end
|
data/lib/mods/record.rb
CHANGED
@@ -22,9 +22,9 @@ module Mods
|
|
22
22
|
end
|
23
23
|
|
24
24
|
# convenience method to call Mods::Reader.new.from_str and to nom
|
25
|
-
# @param ns_aware true if the XML parsing should be strict about using namespaces. Default is
|
25
|
+
# @param ns_aware true if the XML parsing should be strict about using namespaces. Default is true
|
26
26
|
# @param str - a string containing mods xml
|
27
|
-
def from_str(str, ns_aware =
|
27
|
+
def from_str(str, ns_aware = true)
|
28
28
|
@mods_ng_xml = Mods::Reader.new(ns_aware).from_str(str)
|
29
29
|
if ns_aware
|
30
30
|
set_terminology_ns(@mods_ng_xml)
|
@@ -34,9 +34,9 @@ module Mods
|
|
34
34
|
end
|
35
35
|
|
36
36
|
# convenience method to call Mods::Reader.new.from_url and to nom
|
37
|
-
# @param namespace_aware true if the XML parsing should be strict about using namespaces. Default is
|
37
|
+
# @param namespace_aware true if the XML parsing should be strict about using namespaces. Default is true
|
38
38
|
# @param url (String) - url that has mods xml as its content
|
39
|
-
def from_url(url, namespace_aware =
|
39
|
+
def from_url(url, namespace_aware = true)
|
40
40
|
@mods_ng_xml = Mods::Reader.new(ns_aware).from_url(url)
|
41
41
|
if ns_aware
|
42
42
|
set_terminology_ns(@mods_ng_xml)
|
@@ -46,9 +46,9 @@ module Mods
|
|
46
46
|
end
|
47
47
|
|
48
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
|
49
|
+
# @param ns_aware true if the XML parsing should be strict about using namespaces. Default is true
|
50
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 =
|
51
|
+
def from_nk_node(node, ns_aware = true)
|
52
52
|
@mods_ng_xml = Mods::Reader.new(ns_aware).from_nk_node(node)
|
53
53
|
if ns_aware
|
54
54
|
set_terminology_ns(@mods_ng_xml)
|
@@ -142,7 +142,6 @@ module Mods
|
|
142
142
|
result.uniq
|
143
143
|
end
|
144
144
|
|
145
|
-
|
146
145
|
def method_missing method_name, *args
|
147
146
|
if mods_ng_xml.respond_to?(method_name)
|
148
147
|
mods_ng_xml.send(method_name, *args)
|
data/lib/mods/version.rb
CHANGED
data/spec/language_spec.rb
CHANGED
@@ -3,89 +3,116 @@ require 'spec_helper'
|
|
3
3
|
describe "Mods <language> Element" do
|
4
4
|
before(:all) do
|
5
5
|
@mods_rec = Mods::Record.new
|
6
|
-
@simple = '<mods><language>Greek</language></mods>'
|
7
|
-
@simple_ln = @mods_rec.from_str(@simple).language
|
8
|
-
@iso639_2b_code = '<mods><language><languageTerm authority="iso639-2b" type="code">fre</languageTerm></language></mods>'
|
9
|
-
@iso639_2b_code_ln = @mods_rec.from_str(@iso639_2b_code).language
|
10
|
-
@iso639_2b_text = '<mods><language><languageTerm authority="iso639-2b" type="text">English</languageTerm></language></mods>'
|
11
|
-
@iso639_2b_text_ln = @mods_rec.from_str(@iso639_2b_text).language
|
12
|
-
@mult_codes = '<mods><language><languageTerm authority="iso639-2b" type="code">per ara, dut</languageTerm></language></mods>'
|
13
|
-
@mult_codes_ln = @mods_rec.from_str(@mult_codes).language
|
14
|
-
mult_code_terms = '<mods><language><languageTerm authority="iso639-2b" type="code">spa</languageTerm><languageTerm authority="iso639-2b" type="code">dut</languageTerm></language></mods>'
|
15
|
-
@mult_code_terms = @mods_rec.from_str(mult_code_terms).language
|
16
|
-
mult_text_terms = '<mods><language><languageTerm authority="iso639-2b" type="text">Chinese</languageTerm><languageTerm authority="iso639-2b" type="text">Spanish</languageTerm></language></mods>'
|
17
|
-
@mult_text_terms = @mods_rec.from_str(mult_text_terms).language
|
18
|
-
@ex_array = [@simple_ln, @iso639_2b_code_ln, @iso639_2b_text_ln, @mult_codes_ln, @mult_code_terms, @mult_text_terms]
|
19
6
|
end
|
20
7
|
|
21
8
|
context "basic <language> terminology pieces" do
|
22
|
-
before(:all) do
|
23
|
-
@mods_rec.from_str(@iso639_2b_code)
|
24
|
-
end
|
25
|
-
it "should be a NodeSet" do
|
26
|
-
@ex_array.each { |t| t.should be_an_instance_of(Nokogiri::XML::NodeSet) }
|
27
|
-
end
|
28
|
-
it "should have as many members as there are <language> elements in the xml" do
|
29
|
-
@ex_array.each { |t| t.size.should == 1 }
|
30
|
-
end
|
31
9
|
|
32
|
-
context "
|
33
|
-
|
34
|
-
@
|
10
|
+
context "namespace aware" do
|
11
|
+
before(:all) do
|
12
|
+
@ns_decl = "xmlns='#{Mods::MODS_NS}'"
|
13
|
+
@iso639_2b_code = "<mods #{@ns_decl}><language><languageTerm authority='iso639-2b' type='code'>fre</languageTerm></language></mods>"
|
14
|
+
@iso639_2b_code_ln = @mods_rec.from_str(@iso639_2b_code).language
|
15
|
+
mult_code_terms = "<mods #{@ns_decl}><language><languageTerm authority='iso639-2b' type='code'>spa</languageTerm><languageTerm authority='iso639-2b' type='code'>dut</languageTerm></language></mods>"
|
16
|
+
@mult_code_terms = @mods_rec.from_str(mult_code_terms).language
|
17
|
+
mult_text_terms = "<mods #{@ns_decl}><language><languageTerm authority='iso639-2b' type='text'>Chinese</languageTerm><languageTerm authority='iso639-2b' type='text'>Spanish</languageTerm></language></mods>"
|
18
|
+
@mult_text_terms = @mods_rec.from_str(mult_text_terms).language
|
19
|
+
@ex_array = [@iso639_2b_code_ln, @mult_code_terms, @mult_text_terms]
|
35
20
|
end
|
36
|
-
it "should
|
37
|
-
@
|
21
|
+
it "should be a NodeSet" do
|
22
|
+
@ex_array.each { |t| t.should be_an_instance_of(Nokogiri::XML::NodeSet) }
|
38
23
|
end
|
39
|
-
it "should
|
40
|
-
@
|
41
|
-
@iso639_2b_code_ln.languageTerm.size.should == 1
|
24
|
+
it "should have as many members as there are <language> elements in the xml" do
|
25
|
+
@ex_array.each { |t| t.size.should == 1 }
|
42
26
|
end
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
@
|
47
|
-
|
48
|
-
|
27
|
+
|
28
|
+
context "<languageTerm> child element" do
|
29
|
+
it "should understand languageTerm.type_at attribute" do
|
30
|
+
@iso639_2b_code_ln.languageTerm.type_at.should == ["code"]
|
31
|
+
end
|
32
|
+
it "should understand languageTerm.authority attribute" do
|
33
|
+
@iso639_2b_code_ln.languageTerm.authority.should == ["iso639-2b"]
|
34
|
+
end
|
35
|
+
it "should understand languageTerm value" do
|
36
|
+
@iso639_2b_code_ln.languageTerm.text.should == "fre"
|
37
|
+
@iso639_2b_code_ln.languageTerm.size.should == 1
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should recognize all authority attributes" do
|
41
|
+
Mods::AUTHORITY_ATTRIBS.each { |a|
|
42
|
+
@mods_rec.from_str("<mods #{@ns_decl}><language><languageTerm #{a}='attr_val'>zzz</languageTerm></language></mods>")
|
43
|
+
@mods_rec.language.languageTerm.send(a.to_sym).should == ['attr_val']
|
44
|
+
}
|
45
|
+
end
|
46
|
+
end # <languageTerm>
|
47
|
+
|
48
|
+
it "should get one language.code_term for each languageTerm element with a type attribute of 'code'" do
|
49
|
+
@iso639_2b_code_ln.code_term.size.should == 1
|
50
|
+
@iso639_2b_code_ln.code_term.text.should == "fre"
|
51
|
+
@mult_code_terms.code_term.size.should == 2
|
52
|
+
@mult_code_terms.code_term.first.text.should include("spa")
|
53
|
+
@mult_code_terms.code_term[1].text.should == "dut"
|
49
54
|
end
|
50
|
-
|
55
|
+
it "should get one language.text_term for each languageTerm element with a type attribute of 'text'" do
|
56
|
+
@mult_text_terms.text_term.size.should == 2
|
57
|
+
@mult_text_terms.text_term.first.text.should include("Chinese")
|
58
|
+
@mult_text_terms.text_term[1].text.should == "Spanish"
|
59
|
+
end
|
60
|
+
end # namespace_aware
|
61
|
+
|
51
62
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
63
|
+
context "NOT namespace aware" do
|
64
|
+
before(:all) do
|
65
|
+
@iso639_2b_code = "<mods><language><languageTerm authority='iso639-2b' type='code'>fre</languageTerm></language></mods>"
|
66
|
+
@iso639_2b_code_ln = @mods_rec.from_str(@iso639_2b_code, false).language
|
67
|
+
mult_code_terms = "<mods><language><languageTerm authority='iso639-2b' type='code'>spa</languageTerm><languageTerm authority='iso639-2b' type='code'>dut</languageTerm></language></mods>"
|
68
|
+
@mult_code_terms = @mods_rec.from_str(mult_code_terms, false).language
|
69
|
+
mult_text_terms = "<mods><language><languageTerm authority='iso639-2b' type='text'>Chinese</languageTerm><languageTerm authority='iso639-2b' type='text'>Spanish</languageTerm></language></mods>"
|
70
|
+
@mult_text_terms = @mods_rec.from_str(mult_text_terms, false).language
|
71
|
+
@ex_array = [@iso639_2b_code_ln, @mult_code_terms, @mult_text_terms]
|
72
|
+
end
|
73
|
+
it "should be a NodeSet" do
|
74
|
+
@ex_array.each { |t| t.should be_an_instance_of(Nokogiri::XML::NodeSet) }
|
75
|
+
end
|
76
|
+
it "should have as many members as there are <language> elements in the xml" do
|
77
|
+
@ex_array.each { |t| t.size.should == 1 }
|
78
|
+
end
|
79
|
+
|
80
|
+
context "<languageTerm> child element" do
|
81
|
+
it "should understand languageTerm.type_at attribute" do
|
82
|
+
@iso639_2b_code_ln.languageTerm.type_at.should == ["code"]
|
83
|
+
end
|
84
|
+
it "should understand languageTerm.authority attribute" do
|
85
|
+
@iso639_2b_code_ln.languageTerm.authority.should == ["iso639-2b"]
|
86
|
+
end
|
87
|
+
it "should understand languageTerm value" do
|
88
|
+
@iso639_2b_code_ln.languageTerm.text.should == "fre"
|
89
|
+
@iso639_2b_code_ln.languageTerm.size.should == 1
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should recognize all authority attributes" do
|
93
|
+
Mods::AUTHORITY_ATTRIBS.each { |a|
|
94
|
+
@mods_rec.from_str("<mods><language><languageTerm #{a}='attr_val'>zzz</languageTerm></language></mods>", false)
|
95
|
+
@mods_rec.language.languageTerm.send(a.to_sym).should == ['attr_val']
|
96
|
+
}
|
97
|
+
end
|
98
|
+
end # <languageTerm>
|
99
|
+
|
100
|
+
it "should get one language.code_term for each languageTerm element with a type attribute of 'code'" do
|
101
|
+
@iso639_2b_code_ln.code_term.size.should == 1
|
102
|
+
@iso639_2b_code_ln.code_term.text.should == "fre"
|
103
|
+
@mult_code_terms.code_term.size.should == 2
|
104
|
+
@mult_code_terms.code_term.first.text.should include("spa")
|
105
|
+
@mult_code_terms.code_term[1].text.should == "dut"
|
106
|
+
end
|
107
|
+
it "should get one language.text_term for each languageTerm element with a type attribute of 'text'" do
|
108
|
+
@mult_text_terms.text_term.size.should == 2
|
109
|
+
@mult_text_terms.text_term.first.text.should include("Chinese")
|
110
|
+
@mult_text_terms.text_term[1].text.should == "Spanish"
|
111
|
+
end
|
112
|
+
end # NOT namespace_aware
|
113
|
+
|
64
114
|
end # basic <language> terminology pieces
|
65
115
|
|
66
|
-
|
67
|
-
|
68
|
-
it "should translate iso639-2b codes to English" do
|
69
|
-
@mods_rec.from_str(@iso639_2b_code)
|
70
|
-
@mods_rec.languages.should == ["French"]
|
71
|
-
end
|
72
|
-
|
73
|
-
it "should pass thru language values that are already text (not code)" do
|
74
|
-
@mods_rec.from_str(@iso639_2b_text)
|
75
|
-
@mods_rec.languages.should == ["English"]
|
76
|
-
end
|
77
|
-
|
78
|
-
it "should keep values that are not inside <languageTerm> elements" do
|
79
|
-
@mods_rec.from_str(@simple)
|
80
|
-
@mods_rec.languages.should == ["Greek"]
|
81
|
-
end
|
82
|
-
|
83
|
-
it "should create a separate value for each language in a comma, space, or | separated list " do
|
84
|
-
@mods_rec.from_str(@mult_codes)
|
85
|
-
@mods_rec.languages.should include("Arabic")
|
86
|
-
@mods_rec.languages.should include("Persian")
|
87
|
-
@mods_rec.languages.should include("Dutch; Flemish")
|
88
|
-
end
|
89
|
-
end
|
116
|
+
# note that Mods::Record.languages tests are in record_spec
|
90
117
|
|
91
118
|
end
|
data/spec/location_spec.rb
CHANGED
@@ -3,143 +3,293 @@ require 'spec_helper'
|
|
3
3
|
describe "Mods <location> Element" do
|
4
4
|
before(:all) do
|
5
5
|
@mods_rec = Mods::Record.new
|
6
|
-
@url_and_phys = '<mods><location>
|
7
|
-
<url displayLabel="Digital collection of 46 images available online" usage="primary display">http://searchworks.stanford.edu/?f%5Bcollection%5D%5B%5D=The+Reid+W.+Dennis+Collection+of+California+Lithographs&view=gallery</url>
|
8
|
-
</location><location>
|
9
|
-
<physicalLocation>Department of Special Collections, Stanford University Libraries, Stanford, CA 94305.</physicalLocation>
|
10
|
-
</location></mods>'
|
11
|
-
# from http://www.loc.gov/standards/mods/v3/mods-userguide-elements.html !!
|
12
|
-
# sublocation is not allowed directly under location
|
13
|
-
@incorrect = '<mods><location>
|
14
|
-
<physicalLocation>Library of Congress </physicalLocation>
|
15
|
-
<sublocation>Prints and Photographs Division Washington, D.C. 20540 USA</sublocation>
|
16
|
-
<shelfLocator>DAG no. 1410</shelfLocator>
|
17
|
-
</location></mods>'
|
18
6
|
end
|
19
7
|
|
20
8
|
context "basic location terminology pieces" do
|
21
9
|
|
22
|
-
context "
|
10
|
+
context "WITH namespaces" do
|
23
11
|
before(:all) do
|
24
|
-
@
|
25
|
-
@
|
12
|
+
@ns_decl = "xmlns='#{Mods::MODS_NS}'"
|
13
|
+
@url_and_phys = "<mods #{@ns_decl}><location>
|
14
|
+
<url displayLabel='Digital collection of 46 images available online' usage='primary display'>http://searchworks.stanford.edu/?f%5Bcollection%5D%5B%5D=The+Reid+W.+Dennis+Collection+of+California+Lithographs&view=gallery</url>
|
15
|
+
</location><location>
|
16
|
+
<physicalLocation>Department of Special Collections, Stanford University Libraries, Stanford, CA 94305.</physicalLocation>
|
17
|
+
</location></mods>"
|
18
|
+
# from http://www.loc.gov/standards/mods/v3/mods-userguide-elements.html !!
|
19
|
+
# sublocation is not allowed directly under location
|
20
|
+
@incorrect = "<mods #{@ns_decl}><location>
|
21
|
+
<physicalLocation>Library of Congress </physicalLocation>
|
22
|
+
<sublocation>Prints and Photographs Division Washington, D.C. 20540 USA</sublocation>
|
23
|
+
<shelfLocator>DAG no. 1410</shelfLocator>
|
24
|
+
</location></mods>"
|
26
25
|
end
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
26
|
+
|
27
|
+
context "physicalLocation child element" do
|
28
|
+
before(:all) do
|
29
|
+
@phys_loc_only = "<mods #{@ns_decl}><location><physicalLocation>here</physicalLocation></location></mods>"
|
30
|
+
@phys_loc_authority = "<mods #{@ns_decl}><location><physicalLocation authority='marcorg'>MnRM</physicalLocation></location></mods>"
|
31
|
+
end
|
32
|
+
it "should have access to text value of element" do
|
33
|
+
@mods_rec.from_str(@phys_loc_only)
|
34
|
+
@mods_rec.location.physicalLocation.text.should == "here"
|
35
|
+
@mods_rec.from_str(@phys_loc_authority)
|
36
|
+
@mods_rec.location.physicalLocation.map { |n| n.text }.should == ["MnRM"]
|
37
|
+
end
|
38
|
+
it "should recognize authority attribute" do
|
39
|
+
@mods_rec.from_str(@phys_loc_authority)
|
40
|
+
@mods_rec.location.physicalLocation.authority.should == ["marcorg"]
|
41
|
+
end
|
42
|
+
it "should recognize displayLabel attribute" do
|
43
|
+
@mods_rec.from_str("<mods #{@ns_decl}><location><physicalLocation displayLabel='Correspondence'>some address</physicalLocation></location></mods>")
|
44
|
+
@mods_rec.location.physicalLocation.displayLabel.should == ["Correspondence"]
|
45
|
+
end
|
32
46
|
end
|
33
|
-
|
34
|
-
|
35
|
-
|
47
|
+
|
48
|
+
it "shelfLocator child element" do
|
49
|
+
shelf_loc = "<mods #{@ns_decl}><location>
|
50
|
+
<physicalLocation>Library of Congress </physicalLocation>
|
51
|
+
<shelfLocator>DAG no. 1410</shelfLocator>
|
52
|
+
</location></mods>"
|
53
|
+
@mods_rec.from_str(shelf_loc)
|
54
|
+
@mods_rec.location.shelfLocator.map { |n| n.text }.should == ["DAG no. 1410"]
|
36
55
|
end
|
37
|
-
it "should recognize displayLabel attribute" do
|
38
|
-
@mods_rec.from_str('<mods><location><physicalLocation displayLabel="Correspondence">some address</physicalLocation></location></mods>')
|
39
|
-
@mods_rec.location.physicalLocation.displayLabel.should == ["Correspondence"]
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
it "shelfLocator child element" do
|
44
|
-
shelf_loc = '<mods><location>
|
45
|
-
<physicalLocation>Library of Congress </physicalLocation>
|
46
|
-
<shelfLocator>DAG no. 1410</shelfLocator>
|
47
|
-
</location></mods>'
|
48
|
-
@mods_rec.from_str(shelf_loc)
|
49
|
-
@mods_rec.location.shelfLocator.map { |n| n.text }.should == ["DAG no. 1410"]
|
50
|
-
end
|
51
56
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
57
|
+
context "url child element" do
|
58
|
+
before(:all) do
|
59
|
+
@empty_loc_url = "<mods #{@ns_decl}><location><url/></location></mods>"
|
60
|
+
@mult_flavor_loc_urls = "<mods #{@ns_decl}><location>
|
61
|
+
<url access='preview'>http://preview.org</url>
|
62
|
+
<url access='object in context'>http://context.org</url>
|
63
|
+
<url access='raw object'>http://object.org</url>
|
64
|
+
</location></mods>"
|
65
|
+
end
|
66
|
+
it "should have access to text value of element" do
|
67
|
+
urls = @mods_rec.from_str(@mult_flavor_loc_urls).location.url.map { |e| e.text }
|
68
|
+
urls.size.should == 3
|
69
|
+
urls.should include("http://preview.org")
|
70
|
+
urls.should include("http://context.org")
|
71
|
+
urls.should include("http://object.org")
|
72
|
+
end
|
73
|
+
context "attributes" do
|
74
|
+
before(:all) do
|
75
|
+
@url_attribs = "<mods #{@ns_decl}><location>
|
76
|
+
<url displayLabel='Digital collection of 46 images available online' usage='primary display'>http://searchworks.stanford.edu/?f%5Bcollection%5D%5B%5D=The+Reid+W.+Dennis+Collection+of+California+Lithographs&view=gallery</url>
|
77
|
+
</location></mods>"
|
78
|
+
end
|
79
|
+
it "should recognize displayLabel attribute" do
|
80
|
+
@mods_rec.from_str(@url_attribs).location.url.displayLabel.should == ["Digital collection of 46 images available online"]
|
81
|
+
end
|
82
|
+
it "should recognize access attribute" do
|
83
|
+
vals = @mods_rec.from_str(@mult_flavor_loc_urls).location.url.access
|
84
|
+
vals.size.should == 3
|
85
|
+
vals.should include("preview")
|
86
|
+
vals.should include("object in context")
|
87
|
+
vals.should include("raw object")
|
88
|
+
end
|
89
|
+
it "should recognize usage attribute" do
|
90
|
+
@mods_rec.from_str(@url_attribs).location.url.usage.should == ["primary display"]
|
91
|
+
end
|
92
|
+
it "should recognize note attribute" do
|
93
|
+
@mods_rec.from_str("<mods #{@ns_decl}><location><url note='something'>http://somewhere.org</url></location></mods>")
|
94
|
+
@mods_rec.location.url.note.should == ["something"]
|
95
|
+
end
|
96
|
+
it "should recognize dateLastAccessed attribute" do
|
97
|
+
@mods_rec.from_str("<mods #{@ns_decl}><location><url dateLastAccessed='something'>http://somewhere.org</url></location></mods>")
|
98
|
+
@mods_rec.location.url.dateLastAccessed.should == ["something"]
|
99
|
+
end
|
100
|
+
end # attributes
|
101
|
+
it "should have array with empty string for single empty url element" do
|
102
|
+
@mods_rec.from_str(@empty_loc_url).location.url.map { |n| n.text }.should == [""]
|
103
|
+
end
|
104
|
+
end # url child element
|
105
|
+
|
106
|
+
it "holdingSimple child element" do
|
107
|
+
xml = "<mods #{@ns_decl}><location>
|
108
|
+
<physicalLocation authority='marcorg'>MnRM</physicalLocation>
|
109
|
+
<holdingSimple>
|
110
|
+
<copyInformation>
|
111
|
+
<sublocation>Patient reading room</sublocation>
|
112
|
+
<shelfLocator>QH511.A1J68</shelfLocator>
|
113
|
+
<enumerationAndChronology unitType='1'> v.1-v.8 1970-1976</enumerationAndChronology>
|
114
|
+
</copyInformation>
|
115
|
+
</holdingSimple></location></mods>"
|
116
|
+
@mods_rec.from_str(xml).location.holdingSimple.should be_an_instance_of(Nokogiri::XML::NodeSet)
|
117
|
+
@mods_rec.from_str(xml).location.holdingSimple.first.should be_an_instance_of(Nokogiri::XML::Element)
|
60
118
|
end
|
61
|
-
it "
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
119
|
+
it "holdingComplex child element" do
|
120
|
+
xml = "<mods #{@ns_decl}>
|
121
|
+
<location>
|
122
|
+
<physicalLocation>Menlo Park Public Library</physicalLocation>
|
123
|
+
<holdingExternal>
|
124
|
+
<holding xmlns:iso20775='info:ofi/fmt:xml:xsd:iso20775' xsi:schemaLocation='info:ofi/fmt:xml:xsd:iso20775 http://www.loc.gov/standards/iso20775/N130_ISOholdings_v6_1.xsd'>
|
125
|
+
<institutionIdentifier>
|
126
|
+
<value>JRF</value>
|
127
|
+
<typeOrSource>
|
128
|
+
<pointer>http://worldcat.org/registry/institutions/</pointer>
|
129
|
+
</typeOrSource>
|
130
|
+
</institutionIdentifier>
|
131
|
+
<physicalLocation>Menlo Park Public Library</physicalLocation>
|
132
|
+
<physicalAddress>
|
133
|
+
<text>Menlo Park, CA 94025 United States </text>
|
134
|
+
</physicalAddress>
|
135
|
+
<electronicAddress>
|
136
|
+
<text>http://www.worldcat.org/wcpa/oclc/15550774? page=frame&url=%3D%3FUTF-8%3FB%FaHR0cDovL2NhdGFsb2cucGxzaW5mby5vcmcvc2VhcmNoL2kwMTk1MDM4NjMw%3F%3D&title=Menlo+Park+Public+Library&linktype=opac&detail=JRF%3AMenlo+Park+Public+Library%3APublic&app=wcapi&id=OCL-OCLC+Staff+use</text>
|
137
|
+
</electronicAddress>
|
138
|
+
<holdingSimple>
|
139
|
+
<copiesSummary>
|
140
|
+
<copiesCount>1</copiesCount>
|
141
|
+
</copiesSummary>
|
142
|
+
</holdingSimple>
|
143
|
+
</holding>
|
144
|
+
</holdingExternal>
|
145
|
+
</mods>"
|
146
|
+
@mods_rec.from_str(xml).location.holdingExternal.should be_an_instance_of(Nokogiri::XML::NodeSet)
|
147
|
+
@mods_rec.from_str(xml).location.holdingExternal.first.should be_an_instance_of(Nokogiri::XML::Element)
|
67
148
|
end
|
68
|
-
|
149
|
+
|
150
|
+
end # WITH namespaces
|
151
|
+
|
152
|
+
context "WITHOUT namespaces" do
|
153
|
+
before(:all) do
|
154
|
+
@url_and_phys = '<mods><location>
|
155
|
+
<url displayLabel="Digital collection of 46 images available online" usage="primary display">http://searchworks.stanford.edu/?f%5Bcollection%5D%5B%5D=The+Reid+W.+Dennis+Collection+of+California+Lithographs&view=gallery</url>
|
156
|
+
</location><location>
|
157
|
+
<physicalLocation>Department of Special Collections, Stanford University Libraries, Stanford, CA 94305.</physicalLocation>
|
158
|
+
</location></mods>'
|
159
|
+
# from http://www.loc.gov/standards/mods/v3/mods-userguide-elements.html !!
|
160
|
+
# sublocation is not allowed directly under location
|
161
|
+
@incorrect = '<mods><location>
|
162
|
+
<physicalLocation>Library of Congress </physicalLocation>
|
163
|
+
<sublocation>Prints and Photographs Division Washington, D.C. 20540 USA</sublocation>
|
164
|
+
<shelfLocator>DAG no. 1410</shelfLocator>
|
165
|
+
</location></mods>'
|
166
|
+
end
|
167
|
+
|
168
|
+
context "physicalLocation child element" do
|
69
169
|
before(:all) do
|
70
|
-
@
|
71
|
-
|
72
|
-
</location></mods>'
|
170
|
+
@phys_loc_only = '<mods><location><physicalLocation>here</physicalLocation></location></mods>'
|
171
|
+
@phys_loc_authority = '<mods><location><physicalLocation authority="marcorg">MnRM</physicalLocation></location></mods>'
|
73
172
|
end
|
74
|
-
it "should
|
75
|
-
@mods_rec.from_str(@
|
173
|
+
it "should have access to text value of element" do
|
174
|
+
@mods_rec.from_str(@phys_loc_only, false)
|
175
|
+
@mods_rec.location.physicalLocation.text.should == "here"
|
176
|
+
@mods_rec.from_str(@phys_loc_authority, false)
|
177
|
+
@mods_rec.location.physicalLocation.map { |n| n.text }.should == ["MnRM"]
|
76
178
|
end
|
77
|
-
it "should recognize
|
78
|
-
|
79
|
-
|
80
|
-
vals.should include("preview")
|
81
|
-
vals.should include("object in context")
|
82
|
-
vals.should include("raw object")
|
179
|
+
it "should recognize authority attribute" do
|
180
|
+
@mods_rec.from_str(@phys_loc_authority, false)
|
181
|
+
@mods_rec.location.physicalLocation.authority.should == ["marcorg"]
|
83
182
|
end
|
84
|
-
it "should recognize
|
85
|
-
@mods_rec.from_str(
|
183
|
+
it "should recognize displayLabel attribute" do
|
184
|
+
@mods_rec.from_str('<mods><location><physicalLocation displayLabel="Correspondence">some address</physicalLocation></location></mods>', false)
|
185
|
+
@mods_rec.location.physicalLocation.displayLabel.should == ["Correspondence"]
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
it "shelfLocator child element" do
|
190
|
+
shelf_loc = '<mods><location>
|
191
|
+
<physicalLocation>Library of Congress </physicalLocation>
|
192
|
+
<shelfLocator>DAG no. 1410</shelfLocator>
|
193
|
+
</location></mods>'
|
194
|
+
@mods_rec.from_str(shelf_loc, false)
|
195
|
+
@mods_rec.location.shelfLocator.map { |n| n.text }.should == ["DAG no. 1410"]
|
196
|
+
end
|
197
|
+
|
198
|
+
context "url child element" do
|
199
|
+
before(:all) do
|
200
|
+
@empty_loc_url = '<mods><location><url/></location></mods>'
|
201
|
+
@mult_flavor_loc_urls = '<mods><location>
|
202
|
+
<url access="preview">http://preview.org</url>
|
203
|
+
<url access="object in context">http://context.org</url>
|
204
|
+
<url access="raw object">http://object.org</url>
|
205
|
+
</location></mods>'
|
86
206
|
end
|
87
|
-
it "should
|
88
|
-
@mods_rec.from_str(
|
89
|
-
|
207
|
+
it "should have access to text value of element" do
|
208
|
+
urls = @mods_rec.from_str(@mult_flavor_loc_urls, false).location.url.map { |e| e.text }
|
209
|
+
urls.size.should == 3
|
210
|
+
urls.should include("http://preview.org")
|
211
|
+
urls.should include("http://context.org")
|
212
|
+
urls.should include("http://object.org")
|
90
213
|
end
|
91
|
-
|
92
|
-
|
93
|
-
|
214
|
+
context "attributes" do
|
215
|
+
before(:all) do
|
216
|
+
@url_attribs = '<mods><location>
|
217
|
+
<url displayLabel="Digital collection of 46 images available online" usage="primary display">http://searchworks.stanford.edu/?f%5Bcollection%5D%5B%5D=The+Reid+W.+Dennis+Collection+of+California+Lithographs&view=gallery</url>
|
218
|
+
</location></mods>'
|
219
|
+
end
|
220
|
+
it "should recognize displayLabel attribute" do
|
221
|
+
@mods_rec.from_str(@url_attribs, false).location.url.displayLabel.should == ["Digital collection of 46 images available online"]
|
222
|
+
end
|
223
|
+
it "should recognize access attribute" do
|
224
|
+
vals = @mods_rec.from_str(@mult_flavor_loc_urls, false).location.url.access
|
225
|
+
vals.size.should == 3
|
226
|
+
vals.should include("preview")
|
227
|
+
vals.should include("object in context")
|
228
|
+
vals.should include("raw object")
|
229
|
+
end
|
230
|
+
it "should recognize usage attribute" do
|
231
|
+
@mods_rec.from_str(@url_attribs, false).location.url.usage.should == ["primary display"]
|
232
|
+
end
|
233
|
+
it "should recognize note attribute" do
|
234
|
+
@mods_rec.from_str('<mods><location><url note="something">http://somewhere.org</url></location></mods>', false)
|
235
|
+
@mods_rec.location.url.note.should == ["something"]
|
236
|
+
end
|
237
|
+
it "should recognize dateLastAccessed attribute" do
|
238
|
+
@mods_rec.from_str('<mods><location><url dateLastAccessed="something">http://somewhere.org</url></location></mods>', false)
|
239
|
+
@mods_rec.location.url.dateLastAccessed.should == ["something"]
|
240
|
+
end
|
241
|
+
end # attributes
|
242
|
+
it "should have array with empty string for single empty url element" do
|
243
|
+
@mods_rec.from_str(@empty_loc_url, false).location.url.map { |n| n.text }.should == [""]
|
94
244
|
end
|
95
|
-
end #
|
96
|
-
|
97
|
-
|
245
|
+
end # url child element
|
246
|
+
|
247
|
+
it "holdingSimple child element" do
|
248
|
+
xml = '<mods><location>
|
249
|
+
<physicalLocation authority="marcorg">MnRM</physicalLocation>
|
250
|
+
<holdingSimple>
|
251
|
+
<copyInformation>
|
252
|
+
<sublocation>Patient reading room</sublocation>
|
253
|
+
<shelfLocator>QH511.A1J68</shelfLocator>
|
254
|
+
<enumerationAndChronology unitType="1"> v.1-v.8 1970-1976</enumerationAndChronology>
|
255
|
+
</copyInformation>
|
256
|
+
</holdingSimple></location></mods>'
|
257
|
+
@mods_rec.from_str(xml, false).location.holdingSimple.should be_an_instance_of(Nokogiri::XML::NodeSet)
|
258
|
+
@mods_rec.from_str(xml, false).location.holdingSimple.first.should be_an_instance_of(Nokogiri::XML::Element)
|
98
259
|
end
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
</electronicAddress>
|
133
|
-
<holdingSimple>
|
134
|
-
<copiesSummary>
|
135
|
-
<copiesCount>1</copiesCount>
|
136
|
-
</copiesSummary>
|
137
|
-
</holdingSimple>
|
138
|
-
</holding>
|
139
|
-
</holdingExternal>
|
140
|
-
</mods>'
|
141
|
-
@mods_rec.from_str(xml).location.holdingExternal.should be_an_instance_of(Nokogiri::XML::NodeSet)
|
142
|
-
@mods_rec.from_str(xml).location.holdingExternal.first.should be_an_instance_of(Nokogiri::XML::Element)
|
143
|
-
end
|
260
|
+
it "holdingComplex child element" do
|
261
|
+
xml = '<mods>
|
262
|
+
<location>
|
263
|
+
<physicalLocation>Menlo Park Public Library</physicalLocation>
|
264
|
+
<holdingExternal>
|
265
|
+
<holding xmlns:iso20775="info:ofi/fmt:xml:xsd:iso20775" xsi:schemaLocation="info:ofi/fmt:xml:xsd:iso20775 http://www.loc.gov/standards/iso20775/N130_ISOholdings_v6_1.xsd">
|
266
|
+
<institutionIdentifier>
|
267
|
+
<value>JRF</value>
|
268
|
+
<typeOrSource>
|
269
|
+
<pointer>http://worldcat.org/registry/institutions/</pointer>
|
270
|
+
</typeOrSource>
|
271
|
+
</institutionIdentifier>
|
272
|
+
<physicalLocation>Menlo Park Public Library</physicalLocation>
|
273
|
+
<physicalAddress>
|
274
|
+
<text>Menlo Park, CA 94025 United States </text>
|
275
|
+
</physicalAddress>
|
276
|
+
<electronicAddress>
|
277
|
+
<text>http://www.worldcat.org/wcpa/oclc/15550774? page=frame&url=%3D%3FUTF-8%3FB%FaHR0cDovL2NhdGFsb2cucGxzaW5mby5vcmcvc2VhcmNoL2kwMTk1MDM4NjMw%3F%3D&title=Menlo+Park+Public+Library&linktype=opac&detail=JRF%3AMenlo+Park+Public+Library%3APublic&app=wcapi&id=OCL-OCLC+Staff+use</text>
|
278
|
+
</electronicAddress>
|
279
|
+
<holdingSimple>
|
280
|
+
<copiesSummary>
|
281
|
+
<copiesCount>1</copiesCount>
|
282
|
+
</copiesSummary>
|
283
|
+
</holdingSimple>
|
284
|
+
</holding>
|
285
|
+
</holdingExternal>
|
286
|
+
</mods>'
|
287
|
+
@mods_rec.from_str(xml, false).location.holdingExternal.should be_an_instance_of(Nokogiri::XML::NodeSet)
|
288
|
+
@mods_rec.from_str(xml, false).location.holdingExternal.first.should be_an_instance_of(Nokogiri::XML::Element)
|
289
|
+
end
|
290
|
+
|
291
|
+
end # WITHOUT namespaces
|
292
|
+
|
144
293
|
end
|
294
|
+
|
145
295
|
end
|