mods 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,79 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Mods <physicalDescription> Element" do
4
+ before(:all) do
5
+ @mods_rec = Mods::Record.new
6
+ @extent_only = '<mods><physicalDescription><extent>extent</extent></physicalDescription></mods>'
7
+ @form_and_extent = '<mods><physicalDescription>
8
+ <form authority="smd">map</form>
9
+ <form type="material">foo</form>
10
+ <extent>1 map ; 22 x 18 cm.</extent>
11
+ </physicalDescription></mods>'
12
+ @forms_and_notes = '<mods><physicalDescription>
13
+ <form authority="aat">Graphics</form>
14
+ <form>plain form</form>
15
+ <note displayLabel="Dimensions">dimension text</note>
16
+ <note displayLabel="Condition">condition text</note>
17
+ </physicalDescription></mods>'
18
+ @digital = '<mods><physicalDescription>
19
+ <reformattingQuality>preservation</reformattingQuality>
20
+ <internetMediaType>image/jp2</internetMediaType>
21
+ <digitalOrigin>reformatted digital</digitalOrigin>
22
+ </physicalDescription></mods>'
23
+ end
24
+
25
+ context "basic physical_description terminology pieces" do
26
+ before(:all) do
27
+ @mods_rec.from_str(@form_and_extent)
28
+ end
29
+
30
+ it "extent child element" do
31
+ @mods_rec.from_str(@extent_only)
32
+ @mods_rec.physical_description.extent.map { |n| n.text }.should == ["extent"]
33
+ end
34
+
35
+ context "note child element" do
36
+ before(:all) do
37
+ @mods_rec.from_str(@forms_and_notes)
38
+ end
39
+ it "should understand note element" do
40
+ @mods_rec.physical_description.note.map { |n| n.text }.should == ["dimension text", "condition text"]
41
+ end
42
+ it "should understand displayLabel attribute on note element" do
43
+ @mods_rec.physical_description.note.displayLabel.should == ["Dimensions", "Condition"]
44
+ end
45
+ end
46
+
47
+ context "form child element" do
48
+ before(:all) do
49
+ @mods_rec.from_str(@form_and_extent)
50
+ end
51
+ it "should understand form element" do
52
+ @mods_rec.physical_description.form.map { |n| n.text }.should == ["map", "foo"]
53
+ end
54
+ it "should understand authority attribute on form element" do
55
+ @mods_rec.physical_description.form.authority.should == ["smd"]
56
+ end
57
+ it "should understand type attribute on form element" do
58
+ @mods_rec.physical_description.form.type_at.should == ["material"]
59
+ end
60
+ end
61
+
62
+ context "digital materials" do
63
+ before(:all) do
64
+ @mods_rec.from_str(@digital)
65
+ end
66
+ it "should understand reformattingQuality child element" do
67
+ @mods_rec.physical_description.reformattingQuality.map { |n| n.text }.should == ["preservation"]
68
+ end
69
+ it "should understand digitalOrigin child element" do
70
+ @mods_rec.physical_description.digitalOrigin.map { |n| n.text }.should == ["reformatted digital"]
71
+ end
72
+ it "should understand internetMediaType child element" do
73
+ @mods_rec.physical_description.internetMediaType.map { |n| n.text }.should == ["image/jp2"]
74
+ end
75
+ end
76
+
77
+ end # basic terminology pieces
78
+
79
+ end
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Mods::Reader" do
4
+ before(:all) do
5
+ # url is for a namespaced document
6
+ @example_url = 'http://www.loc.gov/standards/mods/v3/mods99042030_linkedDataAdded.xml'
7
+ @example_no_ns_str = '<mods><note>hi</note></mods>'
8
+ @example_wrong_ns_str = '<mods xmlns="whoops"><note>hi</note></mods>'
9
+ @from_no_ns_str = Mods::Reader.new.from_str(@example_no_ns_str)
10
+ @from_wrong_ns_str = Mods::Reader.new.from_str(@example_wrong_ns_str)
11
+ @from_url = Mods::Reader.new.from_url(@example_url)
12
+ @ns_hash = {'mods' => Mods::MODS_NS}
13
+ end
14
+
15
+ it "from_str should turn an xml string into a Nokogiri::XML::Document object" do
16
+ @from_no_ns_str.class.should == Nokogiri::XML::Document
17
+ @from_wrong_ns_str.class.should == Nokogiri::XML::Document
18
+ end
19
+
20
+ it "from_url should turn the contents at the url into a Nokogiri::XML::Document object" do
21
+ @from_url.class.should == Nokogiri::XML::Document
22
+ end
23
+
24
+ context "namespace awareness" do
25
+ it "should not care about namespace by default" do
26
+ r = Mods::Reader.new
27
+ r.namespace_aware.should == false
28
+ @from_no_ns_str.xpath('/mods/note').text.should == "hi"
29
+ @from_wrong_ns_str.xpath('/mods/note').text.should == "hi"
30
+ # @from_no_ns_str.xpath('/mods:mods/mods:note', @ns_hash).text.should == ""
31
+ # @from_wrong_ns_str.xpath('/mods:mods/mods:note', @ns_hash).text.should == ""
32
+ end
33
+
34
+ it "should be allowed to care about namespaces" do
35
+ r = Mods::Reader.new
36
+ r.namespace_aware = true
37
+ r.from_url(@example_url).root.namespace.href.should == Mods::MODS_NS
38
+ my_from_str_no_ns = r.from_str(@example_no_ns_str)
39
+ my_from_str_no_ns.xpath('/mods:mods/mods:note', @ns_hash).text.should_not == "hi"
40
+ my_from_str_wrong_ns = r.from_str(@example_wrong_ns_str)
41
+ my_from_str_wrong_ns.root.namespace.href.should == 'whoops'
42
+ my_from_str_wrong_ns.xpath('/mods:mods/mods:note', @ns_hash).text.should_not == "hi"
43
+ my_from_str_wrong_ns.xpath('/mods/note').text.should_not == "hi"
44
+ end
45
+ end
46
+
47
+ it "should do something useful when it gets unparseable XML" do
48
+ pending "need to implement error handling for bad xml"
49
+ end
50
+ end
@@ -0,0 +1,21 @@
1
+ # for test coverage
2
+ require 'simplecov'
3
+ require 'simplecov-rcov'
4
+ class SimpleCov::Formatter::MergedFormatter
5
+ def format(result)
6
+ SimpleCov::Formatter::HTMLFormatter.new.format(result)
7
+ SimpleCov::Formatter::RcovFormatter.new.format(result)
8
+ end
9
+ end
10
+ SimpleCov.formatter = SimpleCov::Formatter::MergedFormatter
11
+ SimpleCov.start do
12
+ add_filter "/spec/"
13
+ end
14
+
15
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
16
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
17
+
18
+ require 'mods'
19
+
20
+ #RSpec.configure do |config|
21
+ #end
@@ -0,0 +1,111 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Mods <titleInfo> element" do
4
+
5
+ before(:all) do
6
+ @mods_rec = Mods::Record.new
7
+ end
8
+
9
+ it "should recognize type attribute on titleInfo element" do
10
+ Mods::TitleInfo::TYPES.each { |t|
11
+ @mods_rec.from_str("<mods><titleInfo type='#{t}'>hi</titleInfo></mods>")
12
+ @mods_rec.title_info.type_at.text.should == t
13
+ }
14
+ end
15
+
16
+ it "should recognize subelements" do
17
+ Mods::TitleInfo::SUBELEMENTS.each { |e|
18
+ @mods_rec.from_str("<mods><titleInfo><#{e}>oofda</#{e}></titleInfo></mods>")
19
+ @mods_rec.title_info.send(e).text.should == 'oofda'
20
+ }
21
+ end
22
+
23
+ context "short_title" do
24
+ it "should start with nonSort element" do
25
+ @mods_rec.from_str('<mods><titleInfo><title>Jerk</title><nonSort>The</nonSort></titleInfo></mods>')
26
+ @mods_rec.title_info.short_title.should == ["The Jerk"]
27
+ end
28
+ it "should not include subtitle" do
29
+ @mods_rec.from_str('<mods><titleInfo><title>Jerk</title><subTitle>A Tale of Tourettes</subTitle><nonSort>The</nonSort></titleInfo></mods>')
30
+ @mods_rec.title_info.short_title.should == ["The Jerk"]
31
+ end
32
+ it "Mods::Record.short_titles convenience method should return an Array (multiple titles are legal in Mods)" do
33
+ @mods_rec.from_str('<mods><titleInfo><title>Jerk</title><nonSort>The</nonSort></titleInfo><titleInfo><title>Joke</title></titleInfo></mods>')
34
+ @mods_rec.short_titles.should == ["The Jerk", "Joke"]
35
+ end
36
+ it "should not include alternative titles" do
37
+ @mods_rec.from_str('<mods><titleInfo type="alternative"><title>ta da!</title></titleInfo></mods>')
38
+ @mods_rec.short_titles.should_not include("ta da!")
39
+ @mods_rec.from_str("<mods><titleInfo type='alternative'><title>1</title></titleInfo><titleInfo><title>2</title></titleInfo></mods>")
40
+ @mods_rec.short_titles.should == ['2']
41
+ end
42
+ end
43
+
44
+ context "full_title" do
45
+ it "should start with nonSort element" do
46
+ @mods_rec.from_str('<mods><titleInfo><title>Jerk</title><nonSort>The</nonSort></titleInfo></mods>')
47
+ @mods_rec.title_info.full_title.should == ["The Jerk"]
48
+ end
49
+ it "should include subtitle" do
50
+ @mods_rec.from_str('<mods><titleInfo><title>Jerk</title><subTitle>A Tale of Tourettes</subTitle><nonSort>The</nonSort></titleInfo></mods>')
51
+ @mods_rec.title_info.full_title.should == ["The Jerk A Tale of Tourettes"]
52
+ end
53
+ it "Mods::Record.full_titles convenience method should return an Array (multiple titles are legal in Mods)" do
54
+ @mods_rec.from_str('<mods><titleInfo><title>Jerk</title><nonSort>The</nonSort></titleInfo><titleInfo><title>Joke</title></titleInfo></mods>')
55
+ @mods_rec.full_titles.should == ["The Jerk", "Joke"]
56
+ end
57
+ end
58
+
59
+ context "sort_title" do
60
+ it "should skip nonSort element" do
61
+ @mods_rec.from_str('<mods><titleInfo><title>Jerk</title><nonSort>The</nonSort></titleInfo></mods>')
62
+ @mods_rec.title_info.sort_title.should == ["Jerk"]
63
+ end
64
+ it "should contain title and subtitle" do
65
+ @mods_rec.from_str('<mods><titleInfo><title>Jerk</title><subTitle>A Tale of Tourettes</subTitle><nonSort>The</nonSort></titleInfo></mods>')
66
+ @mods_rec.title_info.sort_title.should == ["Jerk A Tale of Tourettes"]
67
+ end
68
+ it "should be an alternative title if there are no other choices" do
69
+ @mods_rec.from_str("<mods><titleInfo type='alternative'><title>1</title></titleInfo></mods>")
70
+ @mods_rec.title_info.sort_title.should == ['1']
71
+ end
72
+ it "should not be an alternative title if there are other choices" do
73
+ @mods_rec.from_str("<mods><titleInfo type='alternative'><title>1</title></titleInfo><titleInfo><title>2</title></titleInfo></mods>")
74
+ @mods_rec.title_info.sort_title.should == ['2']
75
+ @mods_rec.sort_title.should == '2'
76
+ end
77
+ it "should have a configurable delimiter between title and subtitle" do
78
+ m = Mods::Record.new(' : ')
79
+ m.from_str('<mods><titleInfo><title>Jerk</title><subTitle>A Tale of Tourettes</subTitle><nonSort>The</nonSort></titleInfo></mods>')
80
+ m.title_info.sort_title.should == ["Jerk : A Tale of Tourettes"]
81
+ end
82
+ context "Mods::Record.sort_title convenience method" do
83
+ it "convenience method sort_title in Mods::Record should return a string" do
84
+ @mods_rec.from_str('<mods><titleInfo><title>Jerk</title><subTitle>A Tale of Tourettes</subTitle><nonSort>The</nonSort></titleInfo></mods>')
85
+ @mods_rec.sort_title.should == "Jerk A Tale of Tourettes"
86
+ end
87
+ end
88
+ end
89
+
90
+ context "alternative_title" do
91
+ it "should get an alternative title, if it exists" do
92
+ @mods_rec.from_str('<mods><titleInfo type="alternative"><title>ta da!</title></titleInfo></mods>')
93
+ @mods_rec.title_info.alternative_title.should == ["ta da!"]
94
+ end
95
+ it "Mods::Record.alternative_titles convenience method for getting an Array of alternative titles when there are multiple elements" do
96
+ @mods_rec.from_str("<mods><titleInfo type='alternative'><title>1</title></titleInfo><titleInfo type='alternative'><title>2</title></titleInfo></mods>")
97
+ @mods_rec.alternative_titles.should == ['1', '2']
98
+ @mods_rec.from_str("<mods><titleInfo type='alternative'><title>1</title><title>2</title></titleInfo></mods>")
99
+ @mods_rec.alternative_titles.should == ['12']
100
+ end
101
+ it "should not get an alternative title if type attribute is absent from titleInfo" do
102
+ @mods_rec.from_str('<mods><titleInfo><title>ta da!</title></titleInfo></mods>')
103
+ @mods_rec.alternative_titles.should == []
104
+ end
105
+ it "should not get an alternative title if type attribute from titleInfo is not 'alternative'" do
106
+ @mods_rec.from_str('<mods><titleInfo type="uniform"><title>ta da!</title></titleInfo></mods>')
107
+ @mods_rec.alternative_titles.should == []
108
+ end
109
+ end
110
+
111
+ end
@@ -0,0 +1,32 @@
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 get the text contents of any single simple (cannot have child elements) top level element" do
10
+ Mods::TOP_LEVEL_ELEMENTS_SIMPLE.each { |elname|
11
+ @mods_rec.from_str("<mods><#{elname}>hi</#{elname}></mods>")
12
+ @mods_rec.send(elname.to_sym).map { |e| e.text }.should == ["hi"]
13
+ }
14
+ end
15
+
16
+ it "should get the text contents of any single complex top level element instance with no child elements" do
17
+ pending "to be implemented"
18
+ Mods::TOP_LEVEL_ELEMENTS_COMPLEX.each { |elname|
19
+ @mods_rec.from_str("<mods><#{elname}>hi</#{elname}></mods>")
20
+ @mods_rec.send(elname.to_sym).map { |e| e.text }.should == ["hi"]
21
+ }
22
+ end
23
+
24
+ it "should return an array of strings when there are multiple occurrences of simple top level elements" do
25
+ @mods_rec.from_str('<mods><note>hi</note><note>hello</note></mods>').note.map { |e| e.text }.should == ["hi", "hello"]
26
+ end
27
+
28
+ it "should deal with camelcase vs. ruby underscore convention" do
29
+ pending "need to implement ruby style version of (element/attribute) method names"
30
+ end
31
+
32
+ end
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.2
4
+ version: 0.0.4
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-10-31 00:00:00.000000000 Z
13
+ date: 2012-11-08 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: nokogiri
@@ -28,6 +28,38 @@ dependencies:
28
28
  - - ! '>='
29
29
  - !ruby/object:Gem::Version
30
30
  version: '0'
31
+ - !ruby/object:Gem::Dependency
32
+ name: nom-xml
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ type: :runtime
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: iso-639
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
31
63
  - !ruby/object:Gem::Dependency
32
64
  name: rake
33
65
  requirement: !ruby/object:Gem::Requirement
@@ -124,13 +156,16 @@ dependencies:
124
156
  - - ! '>='
125
157
  - !ruby/object:Gem::Version
126
158
  version: '0'
127
- description: A Ruby gem to parse MODS (Metadata Object Description Schema) records
159
+ description: Parse MODS (Metadata Object Description Schema) records. More information
160
+ about MODS can be found at http://www.loc.gov/standards/mods/
128
161
  email:
129
162
  - ndushay AT stanford.edu
130
163
  - bess AT stanford.edu
131
164
  executables: []
132
165
  extensions: []
133
- extra_rdoc_files: []
166
+ extra_rdoc_files:
167
+ - LICENSE
168
+ - README.rdoc
134
169
  files:
135
170
  - .gitignore
136
171
  - .rvmrc
@@ -141,9 +176,25 @@ files:
141
176
  - README.rdoc
142
177
  - Rakefile
143
178
  - lib/mods.rb
179
+ - lib/mods/constants.rb
180
+ - lib/mods/marc_relator_codes.rb
181
+ - lib/mods/name.rb
182
+ - lib/mods/nom_terminology.rb
183
+ - lib/mods/reader.rb
184
+ - lib/mods/record.rb
185
+ - lib/mods/title_info.rb
144
186
  - lib/mods/version.rb
145
187
  - mods.gemspec
146
- homepage: ''
188
+ - spec/language_spec.rb
189
+ - spec/location_spec.rb
190
+ - spec/name_spec.rb
191
+ - spec/origin_info_spec.rb
192
+ - spec/physical_description_spec.rb
193
+ - spec/reader_spec.rb
194
+ - spec/spec_helper.rb
195
+ - spec/title_spec.rb
196
+ - spec/top_level_elmnts_simple_spec.rb
197
+ homepage: https://github.com/sul-dlss/mods
147
198
  licenses: []
148
199
  post_install_message:
149
200
  rdoc_options: []
@@ -157,7 +208,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
157
208
  version: '0'
158
209
  segments:
159
210
  - 0
160
- hash: 94644165565743159
211
+ hash: 1304587137062887266
161
212
  required_rubygems_version: !ruby/object:Gem::Requirement
162
213
  none: false
163
214
  requirements:
@@ -166,13 +217,21 @@ required_rubygems_version: !ruby/object:Gem::Requirement
166
217
  version: '0'
167
218
  segments:
168
219
  - 0
169
- hash: 94644165565743159
220
+ hash: 1304587137062887266
170
221
  requirements: []
171
222
  rubyforge_project:
172
223
  rubygems_version: 1.8.24
173
224
  signing_key:
174
225
  specification_version: 3
175
- summary: A Ruby gem to parse MODS (Metadata Object Description Schema) records. More
176
- information about MODS can be found at http://www.loc.gov/standards/mods/registry.php.
177
- test_files: []
226
+ summary: Parse MODS (Metadata Object Description Schema) records.
227
+ test_files:
228
+ - spec/language_spec.rb
229
+ - spec/location_spec.rb
230
+ - spec/name_spec.rb
231
+ - spec/origin_info_spec.rb
232
+ - spec/physical_description_spec.rb
233
+ - spec/reader_spec.rb
234
+ - spec/spec_helper.rb
235
+ - spec/title_spec.rb
236
+ - spec/top_level_elmnts_simple_spec.rb
178
237
  has_rdoc: