stanford-mods 1.3.3 → 1.3.4
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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rspec +1 -0
- data/.rubocop.yml +4 -0
- data/Gemfile +1 -0
- data/lib/stanford-mods.rb +5 -5
- data/lib/stanford-mods/date_parsing.rb +245 -0
- data/lib/stanford-mods/origin_info.rb +411 -0
- data/lib/stanford-mods/searchworks.rb +23 -474
- data/lib/stanford-mods/searchworks_subjects.rb +208 -0
- data/lib/stanford-mods/version.rb +1 -1
- data/spec/date_parsing_spec.rb +746 -0
- data/spec/fixtures/spotlight_pub_date_data.rb +316 -0
- data/spec/origin_info_spec.rb +449 -0
- data/spec/searchworks_pub_dates_spec.rb +166 -163
- data/spec/spec_helper.rb +16 -5
- data/stanford-mods.gemspec +2 -0
- metadata +25 -2
@@ -3,209 +3,212 @@ require 'spec_helper'
|
|
3
3
|
|
4
4
|
describe "Date methods (searchworks.rb)" do
|
5
5
|
|
6
|
-
|
7
|
-
@ns_decl = "xmlns='#{Mods::MODS_NS}'"
|
8
|
-
end
|
6
|
+
let(:ns_decl) { "xmlns='#{Mods::MODS_NS}'" }
|
9
7
|
|
10
8
|
context "pub_dates" do
|
11
|
-
it "
|
12
|
-
m = "<mods #{
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
expect(
|
9
|
+
it "puts dateIssued values before dateCreated values" do
|
10
|
+
m = "<mods #{ns_decl}><originInfo>
|
11
|
+
<dateCreated>1904</dateCreated>
|
12
|
+
<dateCreated>1904</dateCreated>
|
13
|
+
<dateIssued>1906</dateIssued>
|
14
|
+
</originInfo></mods>"
|
15
|
+
smods_rec = Stanford::Mods::Record.new
|
16
|
+
smods_rec.from_str(m)
|
17
|
+
expect(smods_rec.pub_dates).to eq(['1906', '1904', '1904'])
|
20
18
|
end
|
21
19
|
end
|
22
20
|
|
23
21
|
context "pub_date" do
|
24
|
-
|
25
|
-
@smods_rec = Stanford::Mods::Record.new
|
26
|
-
end
|
22
|
+
let(:smods_rec) { Stanford::Mods::Record.new }
|
27
23
|
|
28
|
-
it "
|
29
|
-
m = "<mods #{
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
expect(
|
34
|
-
end
|
35
|
-
it "
|
36
|
-
m = "<mods #{
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
expect(
|
41
|
-
end
|
42
|
-
it "
|
43
|
-
m = "<mods #{
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
expect(
|
48
|
-
end
|
49
|
-
it '
|
50
|
-
m = "<mods #{
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
expect(
|
55
|
-
end
|
56
|
-
it '
|
57
|
-
m = "<mods #{
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
m
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
expect(
|
83
|
-
expect(
|
84
|
-
expect(
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
expect(
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
expect(
|
111
|
-
expect(
|
112
|
-
expect(
|
113
|
-
end
|
114
|
-
it '
|
115
|
-
m = "<mods #{
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
expect(
|
120
|
-
expect(
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
expect(
|
24
|
+
it "uses dateCreated if no dateIssued" do
|
25
|
+
m = "<mods #{ns_decl}><originInfo>
|
26
|
+
<dateCreated>1904</dateCreated>
|
27
|
+
</originInfo></mods>"
|
28
|
+
smods_rec.from_str(m)
|
29
|
+
expect(smods_rec.pub_date).to eq('1904')
|
30
|
+
end
|
31
|
+
it "parses date" do
|
32
|
+
m = "<mods #{ns_decl}><originInfo>
|
33
|
+
<dateCreated>Aug. 3rd, 1886</dateCreated>
|
34
|
+
</originInfo></mods>"
|
35
|
+
smods_rec.from_str(m)
|
36
|
+
expect(smods_rec.pub_date).to eq('1886')
|
37
|
+
end
|
38
|
+
it "ignores question marks and square brackets" do
|
39
|
+
m = "<mods #{ns_decl}><originInfo>
|
40
|
+
<dateCreated>Aug. 3rd, [18]86?</dateCreated>
|
41
|
+
</originInfo></mods>"
|
42
|
+
smods_rec.from_str(m)
|
43
|
+
expect(smods_rec.pub_date).to eq('1886')
|
44
|
+
end
|
45
|
+
it 'handles an s after the decade' do
|
46
|
+
m = "<mods #{ns_decl}><originInfo>
|
47
|
+
<dateCreated>early 1890s</dateCreated>
|
48
|
+
</originInfo></mods>"
|
49
|
+
smods_rec.from_str(m)
|
50
|
+
expect(smods_rec.pub_date).to eq('1890')
|
51
|
+
end
|
52
|
+
it 'chooses date ending with CE if there are other choices' do
|
53
|
+
m = "<mods #{ns_decl}><originInfo>
|
54
|
+
<dateIssued>7192 AM (li-Adam) / 1684 CE</dateIssued>
|
55
|
+
</originInfo></mods>"
|
56
|
+
smods_rec.from_str(m)
|
57
|
+
expect(smods_rec.pub_date).to eq('1684')
|
58
|
+
end
|
59
|
+
it 'handles 1865-6 (hyphenated range dates)' do
|
60
|
+
m = "<mods #{ns_decl}><originInfo>
|
61
|
+
<dateIssued>1282 AH / 1865-6 CE</dateIssued>
|
62
|
+
</originInfo></mods>"
|
63
|
+
smods_rec.from_str(m)
|
64
|
+
expect(smods_rec.pub_date).to eq('1865')
|
65
|
+
end
|
66
|
+
it 'takes first occurring 4 digit date in string' do
|
67
|
+
m = "<mods #{ns_decl}><originInfo>
|
68
|
+
<dateCreated>Text dated June 4, 1594; miniatures added by 1596</dateCreated>
|
69
|
+
</originInfo></mods>"
|
70
|
+
smods_rec.from_str(m)
|
71
|
+
expect(smods_rec.pub_date).to eq('1594')
|
72
|
+
end
|
73
|
+
it '3 digit BC dates are "B.C." in pub_date_facet and negative in pub_date_sort, pub_year, and pub_date' do
|
74
|
+
m = "<mods #{ns_decl}><originInfo>
|
75
|
+
<dateCreated>300 B.C.</dateCreated>
|
76
|
+
</originInfo></mods>"
|
77
|
+
smods_rec.from_str(m)
|
78
|
+
expect(smods_rec.pub_year).to eq('-700')
|
79
|
+
expect(smods_rec.pub_date).to eq('-700')
|
80
|
+
expect(smods_rec.pub_date_sort).to eq('-700')
|
81
|
+
expect(smods_rec.pub_date_facet).to eq('300 B.C.')
|
82
|
+
end
|
83
|
+
it '"19th CE" becomes 1800 for pub_date_sort, 19th centruy for pub_date_facet' do
|
84
|
+
m = "<mods #{ns_decl}><originInfo>
|
85
|
+
<dateIssued>13th century AH / 19th CE</dateIssued>
|
86
|
+
</originInfo></mods>"
|
87
|
+
smods_rec.from_str(m)
|
88
|
+
expect(smods_rec.pub_date_facet).to eq('19th century')
|
89
|
+
expect(smods_rec.pub_date_sort).to eq('1800')
|
90
|
+
expect(smods_rec.pub_date).to eq('18--')
|
91
|
+
end
|
92
|
+
it 'takes first of multiple CE dates' do
|
93
|
+
m = "<mods #{ns_decl}><originInfo>
|
94
|
+
<dateIssued>6 Dhu al-Hijjah 923 AH / 1517 CE -- 7 Rabi I 924 AH / 1518 CE</dateIssued>
|
95
|
+
</originInfo></mods>"
|
96
|
+
smods_rec.from_str(m)
|
97
|
+
expect(smods_rec.pub_date).to eq('1517')
|
98
|
+
expect(smods_rec.pub_date_sort).to eq('1517')
|
99
|
+
expect(smods_rec.pub_date_facet).to eq('1517')
|
100
|
+
end
|
101
|
+
it 'handles "Late 14th or early 15th century CE" from walters' do
|
102
|
+
m = "<mods #{ns_decl}><originInfo>
|
103
|
+
<dateIssued>Late 14th or early 15th century CE</dateIssued>
|
104
|
+
</originInfo></mods>"
|
105
|
+
smods_rec.from_str(m)
|
106
|
+
expect(smods_rec.pub_date).to eq('14--')
|
107
|
+
expect(smods_rec.pub_date_sort).to eq('1400')
|
108
|
+
expect(smods_rec.pub_date_facet).to eq('15th century')
|
109
|
+
end
|
110
|
+
it 'explicit 3 digit dates have correct pub_date_sort and pub_date_facet' do
|
111
|
+
m = "<mods #{ns_decl}><originInfo>
|
112
|
+
<dateIssued>966 CE</dateIssued>
|
113
|
+
</originInfo></mods>"
|
114
|
+
smods_rec.from_str(m)
|
115
|
+
expect(smods_rec.pub_date).to eq('966')
|
116
|
+
expect(smods_rec.pub_date_sort).to eq('0966')
|
117
|
+
expect(smods_rec.pub_date_facet).to eq('966')
|
118
|
+
end
|
119
|
+
it 'single digit century dates have correct pub_date_sort and pub_date_facet' do
|
120
|
+
m = "<mods #{ns_decl}><originInfo>
|
121
|
+
<dateIssued>3rd century AH / 9th CE</dateIssued>
|
122
|
+
</originInfo></mods>"
|
123
|
+
smods_rec.from_str(m)
|
124
|
+
expect(smods_rec.pub_date).to eq('8--')
|
125
|
+
expect(smods_rec.pub_date_sort).to eq('0800')
|
126
|
+
expect(smods_rec.pub_date_facet).to eq('9th century')
|
127
|
+
end
|
128
|
+
it 'uses dateIssued without marc encoding for pub_date_display and the one with marc encoding for indexing, sorting and faceting' do
|
129
|
+
m = "<mods #{ns_decl}><originInfo>
|
130
|
+
<dateIssued>[186-?]</dateIssued><dateIssued encoding=\"marc\">1860</dateIssued>
|
131
|
+
</originInfo></mods>"
|
132
|
+
smods_rec.from_str(m)
|
133
|
+
expect(smods_rec.pub_date_display).to eq('[186-?]')
|
134
|
+
expect(smods_rec.pub_date).to eq('1860')
|
135
|
+
expect(smods_rec.pub_date_sort).to eq('1860')
|
136
|
+
expect(smods_rec.pub_date_facet).to eq('1860')
|
137
|
+
end
|
138
|
+
it 'uses dateIssued without marc encoding for pub_date_display and the one with marc encoding for indexing, sorting and faceting' do
|
139
|
+
m = "<mods #{ns_decl}><originInfo>
|
140
|
+
<dateIssued>1860?]</dateIssued><dateIssued encoding=\"marc\">186?</dateIssued>
|
141
|
+
</originInfo></mods>"
|
142
|
+
smods_rec.from_str(m)
|
143
|
+
expect(smods_rec.pub_date_display).to eq('1860?]')
|
144
|
+
expect(smods_rec.pub_date).to eq('1860')
|
145
|
+
expect(smods_rec.pub_date_sort).to eq('1860')
|
146
|
+
expect(smods_rec.pub_date_facet).to eq('1860')
|
129
147
|
end
|
130
148
|
end # pub_date
|
131
149
|
|
132
150
|
context "dates with u notation (198u, 19uu)" do
|
133
151
|
context "single digit u notation (198u)" do
|
134
|
-
|
135
|
-
m = "<mods #{
|
152
|
+
let(:smods_rec) do
|
153
|
+
m = "<mods #{ns_decl}>
|
136
154
|
<originInfo>
|
137
155
|
<dateIssued encoding=\"marc\" point=\"start\" keyDate=\"yes\">198u</dateIssued>
|
138
156
|
<dateIssued encoding=\"marc\" point=\"end\">9999</dateIssued>
|
139
157
|
</originInfo></mods>"
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
it "get_u_year recognizes notation" do
|
144
|
-
dates = ["198u", "9999"]
|
145
|
-
uDate = @smods_rec.get_u_year dates
|
146
|
-
expect(uDate).to eql("1980")
|
158
|
+
smr = Stanford::Mods::Record.new
|
159
|
+
smr.from_str(m)
|
160
|
+
smr
|
147
161
|
end
|
148
162
|
it 'pub_date: 198u = 1980' do
|
149
|
-
expect(
|
163
|
+
expect(smods_rec.pub_date).to eq('1980')
|
150
164
|
end
|
151
165
|
it "pub_date_sort: 198u = 1980" do
|
152
|
-
expect(
|
166
|
+
expect(smods_rec.pub_date_sort).to eq('1980')
|
153
167
|
end
|
154
168
|
it "pub_date_facet: 198u = 1980" do
|
155
|
-
expect(
|
169
|
+
expect(smods_rec.pub_date_facet).to eq('1980')
|
156
170
|
end
|
157
171
|
end
|
158
172
|
context "double digit u notation (19uu)" do
|
159
|
-
|
160
|
-
m = "<mods #{
|
173
|
+
let(:smods_rec) do
|
174
|
+
m = "<mods #{ns_decl}>
|
161
175
|
<originInfo>
|
162
176
|
<dateIssued encoding=\"marc\" point=\"start\" keyDate=\"yes\">19uu</dateIssued>
|
163
177
|
<dateIssued encoding=\"marc\" point=\"end\">9999</dateIssued>
|
164
178
|
</originInfo></mods>"
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
it "get_u_year recognizes notation" do
|
169
|
-
dates = ["19uu", "9999"]
|
170
|
-
uDate = @smods_rec.get_u_year dates
|
171
|
-
expect(uDate).to eql("19--")
|
179
|
+
smr = Stanford::Mods::Record.new
|
180
|
+
smr.from_str(m)
|
181
|
+
smr
|
172
182
|
end
|
173
183
|
it 'pub_date: 19uu = 19--' do
|
174
|
-
expect(
|
184
|
+
expect(smods_rec.pub_date).to eq('19--')
|
175
185
|
end
|
176
186
|
it "pub_date_sort: 19uu = 1900" do
|
177
|
-
expect(
|
187
|
+
expect(smods_rec.pub_date_sort).to eq('1900')
|
178
188
|
end
|
179
189
|
it "pub_date_facet: 19uu = 20th century" do
|
180
|
-
expect(
|
190
|
+
expect(smods_rec.pub_date_facet).to eq('20th century')
|
181
191
|
end
|
182
192
|
end
|
183
193
|
end # u notation
|
184
194
|
|
185
|
-
|
186
195
|
context 'pub_date_sort' do
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
allow(@smods_rec).to receive(:pub_date).and_return('16--')
|
204
|
-
expect(@smods_rec.pub_date_sort).to eq('1600')
|
205
|
-
end
|
206
|
-
it 'should work on 3 digit century dates' do
|
207
|
-
allow(@smods_rec).to receive(:pub_date).and_return('9--')
|
208
|
-
expect(@smods_rec.pub_date_sort).to eq('0900')
|
196
|
+
let(:smods_rec) { Stanford::Mods::Record.new }
|
197
|
+
it 'four digits' do
|
198
|
+
allow(smods_rec).to receive(:pub_date).and_return('1945')
|
199
|
+
expect(smods_rec.pub_date_sort).to eq('1945')
|
200
|
+
end
|
201
|
+
it '3 digits' do
|
202
|
+
allow(smods_rec).to receive(:pub_date).and_return('945')
|
203
|
+
expect(smods_rec.pub_date_sort).to eq('0945')
|
204
|
+
end
|
205
|
+
it '16--' do
|
206
|
+
allow(smods_rec).to receive(:pub_date).and_return('16--')
|
207
|
+
expect(smods_rec.pub_date_sort).to eq('1600')
|
208
|
+
end
|
209
|
+
it '9--' do
|
210
|
+
allow(smods_rec).to receive(:pub_date).and_return('9--')
|
211
|
+
expect(smods_rec.pub_date_sort).to eq('0900')
|
209
212
|
end
|
210
213
|
end
|
211
214
|
|
data/spec/spec_helper.rb
CHANGED
@@ -1,10 +1,21 @@
|
|
1
1
|
require 'coveralls'
|
2
2
|
Coveralls.wear!
|
3
3
|
|
4
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
5
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
6
|
-
|
7
4
|
require 'stanford-mods'
|
8
5
|
|
9
|
-
# RSpec
|
10
|
-
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.expect_with :rspec do |expectations|
|
9
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
10
|
+
end
|
11
|
+
|
12
|
+
config.mock_with :rspec do |mocks|
|
13
|
+
mocks.verify_partial_doubles = true
|
14
|
+
end
|
15
|
+
|
16
|
+
if config.files_to_run.one?
|
17
|
+
config.default_formatter = 'doc'
|
18
|
+
end
|
19
|
+
|
20
|
+
#config.order = :random
|
21
|
+
end
|
data/stanford-mods.gemspec
CHANGED
@@ -17,6 +17,8 @@ Gem::Specification.new do |gem|
|
|
17
17
|
gem.require_paths = ["lib"]
|
18
18
|
|
19
19
|
gem.add_dependency 'mods', '~> 2.0.2'
|
20
|
+
# active_support for .ordinalize, eg. 1 -> 1st, 2 -> 2nd for centuries
|
21
|
+
gem.add_dependency 'activesupport'
|
20
22
|
|
21
23
|
# Runtime dependencies
|
22
24
|
# gem.add_runtime_dependency 'nokogiri'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stanford-mods
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Naomi Dushay
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2016-01-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mods
|
@@ -25,6 +25,20 @@ dependencies:
|
|
25
25
|
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: 2.0.2
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: activesupport
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
28
42
|
- !ruby/object:Gem::Dependency
|
29
43
|
name: rake
|
30
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -106,14 +120,20 @@ files:
|
|
106
120
|
- Rakefile
|
107
121
|
- config/mappings_hash.rb
|
108
122
|
- lib/stanford-mods.rb
|
123
|
+
- lib/stanford-mods/date_parsing.rb
|
109
124
|
- lib/stanford-mods/geo_spatial.rb
|
110
125
|
- lib/stanford-mods/name.rb
|
126
|
+
- lib/stanford-mods/origin_info.rb
|
111
127
|
- lib/stanford-mods/physical_location.rb
|
112
128
|
- lib/stanford-mods/searchworks.rb
|
113
129
|
- lib/stanford-mods/searchworks_languages.rb
|
130
|
+
- lib/stanford-mods/searchworks_subjects.rb
|
114
131
|
- lib/stanford-mods/version.rb
|
132
|
+
- spec/date_parsing_spec.rb
|
133
|
+
- spec/fixtures/spotlight_pub_date_data.rb
|
115
134
|
- spec/geo_spatial_spec.rb
|
116
135
|
- spec/name_spec.rb
|
136
|
+
- spec/origin_info_spec.rb
|
117
137
|
- spec/physical_location_spec.rb
|
118
138
|
- spec/searchworks_basic_spec.rb
|
119
139
|
- spec/searchworks_format_spec.rb
|
@@ -148,8 +168,11 @@ signing_key:
|
|
148
168
|
specification_version: 4
|
149
169
|
summary: Stanford specific wrangling of MODS metadata
|
150
170
|
test_files:
|
171
|
+
- spec/date_parsing_spec.rb
|
172
|
+
- spec/fixtures/spotlight_pub_date_data.rb
|
151
173
|
- spec/geo_spatial_spec.rb
|
152
174
|
- spec/name_spec.rb
|
175
|
+
- spec/origin_info_spec.rb
|
153
176
|
- spec/physical_location_spec.rb
|
154
177
|
- spec/searchworks_basic_spec.rb
|
155
178
|
- spec/searchworks_format_spec.rb
|