stanford-mods 1.1.2 → 1.1.3
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/.rspec +1 -0
- data/README.rdoc +12 -13
- data/Rakefile +3 -5
- data/config/mappings_hash.rb +22 -23
- data/lib/stanford-mods/searchworks.rb +91 -93
- data/lib/stanford-mods/version.rb +1 -1
- data/lib/stanford-mods.rb +7 -7
- data/spec/name_spec.rb +43 -43
- data/spec/searchworks_basic_spec.rb +49 -0
- data/spec/searchworks_format_spec.rb +7 -7
- data/spec/searchworks_pub_dates_spec.rb +50 -52
- data/spec/searchworks_spec.rb +25 -25
- data/spec/searchworks_subject_raw_spec.rb +83 -83
- data/spec/searchworks_subject_spec.rb +97 -93
- data/spec/searchworks_title_spec.rb +10 -10
- data/stanford-mods.gemspec +10 -10
- metadata +24 -21
data/spec/name_spec.rb
CHANGED
@@ -38,7 +38,7 @@ describe "name/author concepts" do
|
|
38
38
|
<namePart>plain_other_role_mr</namePart>
|
39
39
|
<role><roleTerm type='text' authority='marcrelator'>Actor</roleTerm></role>
|
40
40
|
</name>"
|
41
|
-
|
41
|
+
|
42
42
|
@personal_no_role = "<name><namePart type='personal'>personal_no_role</namePart></name>"
|
43
43
|
@personal_creator_code = "<name>
|
44
44
|
<namePart type='personal'>personal_creator_code</namePart>
|
@@ -66,77 +66,77 @@ describe "name/author concepts" do
|
|
66
66
|
context "marcrelator role Creator" do
|
67
67
|
it "should find role with roleTerm type text" do
|
68
68
|
@smods_rec.from_str(@mods_start + @plain_creator_text + @mods_end)
|
69
|
-
@smods_rec.main_author_w_date.
|
69
|
+
expect(@smods_rec.main_author_w_date).to eq('plain_creator_text')
|
70
70
|
end
|
71
71
|
it "should find role with roleTerm type code" do
|
72
72
|
@smods_rec.from_str(@mods_start + @plain_creator_code + @mods_end)
|
73
|
-
@smods_rec.main_author_w_date.
|
73
|
+
expect(@smods_rec.main_author_w_date).to eq('plain_creator_code')
|
74
74
|
end
|
75
75
|
it "should skip names when role isn't marcrelator authority" do
|
76
76
|
@smods_rec.from_str(@mods_start + @plain_creator_non_mr + @mods_end)
|
77
|
-
@smods_rec.main_author_w_date.
|
77
|
+
expect(@smods_rec.main_author_w_date).to be_nil
|
78
78
|
end
|
79
79
|
it "should skip names without roles in favor of marcrelator role of 'Creator'" do
|
80
80
|
@smods_rec.from_str(@mods_start + @personal_no_role + @plain_creator_text + @other_no_role + @mods_end)
|
81
|
-
@smods_rec.main_author_w_date.
|
81
|
+
expect(@smods_rec.main_author_w_date).to eq('plain_creator_text')
|
82
82
|
@smods_rec.from_str(@mods_start + @corp_no_role + @plain_creator_code + @mods_end)
|
83
|
-
@smods_rec.main_author_w_date.
|
83
|
+
expect(@smods_rec.main_author_w_date).to eq('plain_creator_code')
|
84
84
|
end
|
85
85
|
it "shouldn't care about name type" do
|
86
86
|
@smods_rec.from_str(@mods_start + @personal_creator_code + @corp_creator_text + @mods_end)
|
87
|
-
@smods_rec.main_author_w_date.
|
87
|
+
expect(@smods_rec.main_author_w_date).to eq('personal_creator_code')
|
88
88
|
@smods_rec.from_str(@mods_start + @personal_no_role + @corp_creator_text + @mods_end)
|
89
|
-
@smods_rec.main_author_w_date.
|
89
|
+
expect(@smods_rec.main_author_w_date).to eq('corp_creator_text')
|
90
90
|
end
|
91
91
|
end
|
92
|
-
|
92
|
+
|
93
93
|
context "marcrelator role Author" do
|
94
94
|
it "should find role with roleTerm type text" do
|
95
95
|
@smods_rec.from_str(@mods_start + @plain_author_text + @mods_end)
|
96
|
-
@smods_rec.main_author_w_date.
|
96
|
+
expect(@smods_rec.main_author_w_date).to eq('plain_author_text')
|
97
97
|
end
|
98
98
|
it "should find role with roleTerm type code" do
|
99
99
|
@smods_rec.from_str(@mods_start + @plain_author_code + @mods_end)
|
100
|
-
@smods_rec.main_author_w_date.
|
100
|
+
expect(@smods_rec.main_author_w_date).to eq('plain_author_code')
|
101
101
|
end
|
102
102
|
it "should skip names when role isn't marcrelator authority" do
|
103
103
|
@smods_rec.from_str(@mods_start + @plain_author_non_mr + @mods_end)
|
104
|
-
@smods_rec.main_author_w_date.
|
104
|
+
expect(@smods_rec.main_author_w_date).to be_nil
|
105
105
|
end
|
106
106
|
it "should skip names without roles in favor of marcrelator role of 'Author'" do
|
107
107
|
@smods_rec.from_str(@mods_start + @personal_no_role + @plain_author_text + @other_no_role + @mods_end)
|
108
|
-
@smods_rec.main_author_w_date.
|
108
|
+
expect(@smods_rec.main_author_w_date).to eq('plain_author_text')
|
109
109
|
@smods_rec.from_str(@mods_start + @corp_no_role + @personal_no_role + @plain_author_code + @mods_end)
|
110
|
-
@smods_rec.main_author_w_date.
|
110
|
+
expect(@smods_rec.main_author_w_date).to eq('plain_author_code')
|
111
111
|
end
|
112
112
|
it "shouldn't care about name type" do
|
113
113
|
@smods_rec.from_str(@mods_start + @personal_author_text + @corp_author_code + @mods_end)
|
114
|
-
@smods_rec.main_author_w_date.
|
114
|
+
expect(@smods_rec.main_author_w_date).to eq('personal_author_text')
|
115
115
|
@smods_rec.from_str(@mods_start + @personal_no_role + @corp_author_code + @mods_end)
|
116
|
-
@smods_rec.main_author_w_date.
|
116
|
+
expect(@smods_rec.main_author_w_date).to eq('corp_author_code')
|
117
117
|
end
|
118
118
|
end
|
119
|
-
|
119
|
+
|
120
120
|
it "should be a String" do
|
121
121
|
@smods_rec.from_str(@mods_start + @personal_author_text + @corp_creator_text + @mods_end)
|
122
|
-
@smods_rec.main_author_w_date.
|
122
|
+
expect(@smods_rec.main_author_w_date).to be_an_instance_of(String)
|
123
123
|
end
|
124
|
-
|
124
|
+
|
125
125
|
it "should take first name with marcrelator role of 'Creator' or 'Author'" do
|
126
126
|
@smods_rec.from_str(@mods_start + @personal_author_text + @corp_creator_text + @mods_end)
|
127
|
-
@smods_rec.main_author_w_date.
|
127
|
+
expect(@smods_rec.main_author_w_date).to eq('personal_author_text')
|
128
128
|
@smods_rec.from_str(@mods_start + @corp_creator_text + @personal_creator_code + @mods_end)
|
129
|
-
@smods_rec.main_author_w_date.
|
129
|
+
expect(@smods_rec.main_author_w_date).to eq('corp_creator_text')
|
130
130
|
end
|
131
|
-
|
131
|
+
|
132
132
|
it "should take the first name without a role if there are no instances of marcrelator role 'Creator' or 'Actor'" do
|
133
133
|
@smods_rec.from_str(@mods_start + @plain_author_non_mr + @personal_other_role + @personal_no_role + @plain_no_role + @mods_end)
|
134
|
-
@smods_rec.main_author_w_date.
|
134
|
+
expect(@smods_rec.main_author_w_date).to eq('personal_no_role')
|
135
135
|
end
|
136
|
-
|
136
|
+
|
137
137
|
it "should be nil if there is no name with marcrelator role of 'Creator' or 'Author' and no name without a role" do
|
138
138
|
@smods_rec.from_str(@mods_start + @plain_author_non_mr + @personal_other_role + @mods_end)
|
139
|
-
@smods_rec.main_author_w_date.
|
139
|
+
expect(@smods_rec.main_author_w_date).to be_nil
|
140
140
|
end
|
141
141
|
|
142
142
|
it "should use the display name if it is present" do
|
@@ -153,7 +153,7 @@ describe "name/author concepts" do
|
|
153
153
|
</name>
|
154
154
|
</mods>"
|
155
155
|
@smods_rec.from_str(m)
|
156
|
-
@smods_rec.main_author_w_date.
|
156
|
+
expect(@smods_rec.main_author_w_date).to eq('q')
|
157
157
|
end
|
158
158
|
it "should include dates, when available" do
|
159
159
|
m = "<mods #{@ns_decl}><name type='personal'>
|
@@ -161,19 +161,19 @@ describe "name/author concepts" do
|
|
161
161
|
<namePart type='date'>1984-</namePart>
|
162
162
|
</name></mods>"
|
163
163
|
@smods_rec.from_str(m)
|
164
|
-
@smods_rec.main_author_w_date.
|
164
|
+
expect(@smods_rec.main_author_w_date).to eq('personal, 1984-')
|
165
165
|
m = "<mods #{@ns_decl}><name>
|
166
166
|
<namePart>plain</namePart>
|
167
167
|
<namePart type='date'>1954-</namePart>
|
168
168
|
</name></mods>"
|
169
169
|
@smods_rec.from_str(m)
|
170
|
-
@smods_rec.main_author_w_date.
|
170
|
+
expect(@smods_rec.main_author_w_date).to eq('plain, 1954-')
|
171
171
|
m = "<mods #{@ns_decl}><name type='corporate'>
|
172
172
|
<namePart>corporate</namePart>
|
173
173
|
<namePart type='date'>1990-</namePart>
|
174
174
|
</name></mods>"
|
175
175
|
@smods_rec.from_str(m)
|
176
|
-
@smods_rec.main_author_w_date.
|
176
|
+
expect(@smods_rec.main_author_w_date).to eq('corporate, 1990-')
|
177
177
|
end
|
178
178
|
end # main_author_w_date
|
179
179
|
|
@@ -210,33 +210,33 @@ describe "name/author concepts" do
|
|
210
210
|
@addl_authors = @smods_rec.additional_authors_w_dates
|
211
211
|
end
|
212
212
|
it "should be an Array of Strings" do
|
213
|
-
@addl_authors.
|
214
|
-
@addl_authors.first.
|
213
|
+
expect(@addl_authors).to be_an_instance_of(Array)
|
214
|
+
expect(@addl_authors.first).to be_an_instance_of(String)
|
215
215
|
end
|
216
216
|
it "should not include main author" do
|
217
|
-
@addl_authors.
|
217
|
+
expect(@addl_authors).not_to include(@smods_rec.main_author_w_date)
|
218
218
|
end
|
219
219
|
it "should include personal authors that are not main author" do
|
220
|
-
@addl_authors.
|
220
|
+
expect(@addl_authors).to include('Crusty The Clown, 1990-')
|
221
221
|
end
|
222
222
|
it "should include corporate (and other) authors that are not main author" do
|
223
|
-
@addl_authors.
|
224
|
-
@addl_authors.
|
223
|
+
expect(@addl_authors).to include('Watchful Eye, 1850-')
|
224
|
+
expect(@addl_authors).to include('Exciting Prints')
|
225
225
|
end
|
226
226
|
it "should include plain authors" do
|
227
|
-
@addl_authors.
|
227
|
+
expect(@addl_authors).to include('plain')
|
228
228
|
end
|
229
229
|
it "should include conference and other typed authors" do
|
230
|
-
@addl_authors.
|
231
|
-
@addl_authors.
|
230
|
+
expect(@addl_authors).to include('conference')
|
231
|
+
expect(@addl_authors).to include('family')
|
232
232
|
end
|
233
233
|
it "should include dates, when available" do
|
234
|
-
@addl_authors.
|
235
|
-
@addl_authors.
|
234
|
+
expect(@addl_authors).to include('Crusty The Clown, 1990-')
|
235
|
+
expect(@addl_authors).to include('Watchful Eye, 1850-')
|
236
236
|
end
|
237
237
|
it "should not include roles" do
|
238
|
-
@addl_authors.find { |a| a =~ Regexp.new('lithographer') }.
|
238
|
+
expect(@addl_authors.find { |a| a =~ Regexp.new('lithographer') }).to be_nil
|
239
239
|
end
|
240
240
|
end # additional_authors_w_dates
|
241
|
-
|
242
|
-
end
|
241
|
+
|
242
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# require 'spec_helper'
|
2
|
+
# not using spec_helper here: testing require
|
3
|
+
require 'stanford-mods/searchworks'
|
4
|
+
|
5
|
+
describe 'Basic construction' do
|
6
|
+
before(:each) do
|
7
|
+
@dsxml =<<-EOF
|
8
|
+
<mods xmlns="http://www.loc.gov/mods/v3"
|
9
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="3.3"
|
10
|
+
xsi:schemaLocation="http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-3.xsd">
|
11
|
+
<titleInfo>
|
12
|
+
<title>Electronic Theses and Dissertations</title>
|
13
|
+
</titleInfo>
|
14
|
+
<abstract>Abstract contents.</abstract>
|
15
|
+
<name type="corporate">
|
16
|
+
<namePart>Stanford University Libraries, Stanford Digital Repository</namePart>
|
17
|
+
<role>
|
18
|
+
<roleTerm authority="marcrelator" type="text">creator</roleTerm>
|
19
|
+
</role>
|
20
|
+
</name>
|
21
|
+
<typeOfResource collection="yes"/>
|
22
|
+
<language>
|
23
|
+
<languageTerm authority="iso639-2b" type="code">eng</languageTerm>
|
24
|
+
</language>
|
25
|
+
<subject>
|
26
|
+
<geographic>First Place</geographic>
|
27
|
+
<geographic>Other Place, Nation;</geographic>
|
28
|
+
<temporal>1890-1910</temporal>
|
29
|
+
<temporal>20th century</temporal>
|
30
|
+
<topic>Topic1: Boring Part</topic>
|
31
|
+
</subject>
|
32
|
+
<subject><temporal>another</temporal></subject>
|
33
|
+
<genre>first</genre>
|
34
|
+
<genre>second</genre>
|
35
|
+
<subject><topic>Topic2: The Interesting Part!</topic></subject>
|
36
|
+
</mods>
|
37
|
+
EOF
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "from_str" do
|
41
|
+
it "should work" do
|
42
|
+
m = Stanford::Mods::Record.new
|
43
|
+
expect(m).not_to be_nil
|
44
|
+
m.from_str(@dsxml)
|
45
|
+
expect(m).not_to be_nil
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
@@ -93,7 +93,7 @@ describe "Format fields (searchworks.rb)" do
|
|
93
93
|
end
|
94
94
|
end
|
95
95
|
end # 'Book'
|
96
|
-
|
96
|
+
|
97
97
|
context "Computer File: typeOfResource 'software, multimedia'" do
|
98
98
|
it "no genre (e.g. Dataset)" do
|
99
99
|
m = "<mods #{@ns_decl}><typeOfResource>software, multimedia</typeOfResource></mods>"
|
@@ -121,7 +121,7 @@ describe "Format fields (searchworks.rb)" do
|
|
121
121
|
@smods_rec.from_str(m)
|
122
122
|
expect(@smods_rec.format).to eq ['Conference Proceedings']
|
123
123
|
end
|
124
|
-
|
124
|
+
|
125
125
|
context "Journal/Periodical: typeOfResource 'text'," do
|
126
126
|
it "genre 'article" do
|
127
127
|
m = "<mods #{@ns_decl}><typeOfResource>text</typeOfResource><genre>article</genre></mods>"
|
@@ -143,7 +143,7 @@ describe "Format fields (searchworks.rb)" do
|
|
143
143
|
@smods_rec.from_str(m)
|
144
144
|
expect(@smods_rec.format).to eq ['Image']
|
145
145
|
end
|
146
|
-
|
146
|
+
|
147
147
|
it "Manuscript/Archive: typeOfResource 'mixed material'" do
|
148
148
|
m = "<mods #{@ns_decl}><typeOfResource>mixed material</typeOfResource></mods>"
|
149
149
|
@smods_rec.from_str(m)
|
@@ -155,7 +155,7 @@ describe "Format fields (searchworks.rb)" do
|
|
155
155
|
@smods_rec.from_str(m)
|
156
156
|
expect(@smods_rec.format).to eq ['Map/Globe']
|
157
157
|
end
|
158
|
-
|
158
|
+
|
159
159
|
it "Music - Recording: typeOfResource 'sound recording-musical'", :jira => 'GRYPHONDOR-207' do
|
160
160
|
m = "<mods #{@ns_decl}><typeOfResource>sound recording-musical</typeOfResource></mods>"
|
161
161
|
@smods_rec.from_str(m)
|
@@ -182,7 +182,7 @@ describe "Format fields (searchworks.rb)" do
|
|
182
182
|
@smods_rec.from_str(m)
|
183
183
|
expect(@smods_rec.format).to eq ['Other']
|
184
184
|
end
|
185
|
-
|
185
|
+
|
186
186
|
context "Sound Recording:" do
|
187
187
|
it "typeOfResource 'sound recording-nonmusical', genre 'sound", :jira => 'GRYPHONDOR-207' do
|
188
188
|
m = "<mods #{@ns_decl}><genre>sound</genre><typeOfResource>sound recording-nonmusical</typeOfResource></mods>"
|
@@ -269,7 +269,7 @@ describe "Format fields (searchworks.rb)" do
|
|
269
269
|
expect(@smods_rec.format).to eq []
|
270
270
|
end
|
271
271
|
end # format
|
272
|
-
|
272
|
+
|
273
273
|
context "format_main" do
|
274
274
|
it "3D object: typeOfResource 'three dimensional object'" do
|
275
275
|
m = "<mods #{@ns_decl}><typeOfResource>three dimensional object</typeOfResource></mods>"
|
@@ -628,4 +628,4 @@ describe "Format fields (searchworks.rb)" do
|
|
628
628
|
expect(@smods_rec.sw_genre).to eq []
|
629
629
|
end
|
630
630
|
end # sw_genre
|
631
|
-
end
|
631
|
+
end
|
@@ -7,7 +7,7 @@ describe "Date methods (searchworks.rb)" do
|
|
7
7
|
@smods_rec = Stanford::Mods::Record.new
|
8
8
|
@ns_decl = "xmlns='#{Mods::MODS_NS}'"
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
context "pub_dates" do
|
12
12
|
it "should choose the first date" do
|
13
13
|
m = "<mods #{@ns_decl}><originInfo>
|
@@ -17,7 +17,7 @@ describe "Date methods (searchworks.rb)" do
|
|
17
17
|
</originInfo></mods>"
|
18
18
|
@smods_rec = Stanford::Mods::Record.new
|
19
19
|
@smods_rec.from_str(m)
|
20
|
-
@smods_rec.pub_dates.
|
20
|
+
expect(@smods_rec.pub_dates).to eq(['1906','1904','1904'])
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -28,7 +28,7 @@ describe "Date methods (searchworks.rb)" do
|
|
28
28
|
</originInfo></mods>"
|
29
29
|
@smods_rec = Stanford::Mods::Record.new
|
30
30
|
@smods_rec.from_str(m)
|
31
|
-
@smods_rec.pub_date.
|
31
|
+
expect(@smods_rec.pub_date).to eq('1904')
|
32
32
|
end
|
33
33
|
it "should parse a date" do
|
34
34
|
m = "<mods #{@ns_decl}><originInfo>
|
@@ -36,7 +36,7 @@ describe "Date methods (searchworks.rb)" do
|
|
36
36
|
</originInfo></mods>"
|
37
37
|
@smods_rec = Stanford::Mods::Record.new
|
38
38
|
@smods_rec.from_str(m)
|
39
|
-
@smods_rec.pub_date.
|
39
|
+
expect(@smods_rec.pub_date).to eq('1886')
|
40
40
|
end
|
41
41
|
it "should remove question marks and brackets" do
|
42
42
|
m = "<mods #{@ns_decl}><originInfo>
|
@@ -44,7 +44,7 @@ describe "Date methods (searchworks.rb)" do
|
|
44
44
|
</originInfo></mods>"
|
45
45
|
@smods_rec = Stanford::Mods::Record.new
|
46
46
|
@smods_rec.from_str(m)
|
47
|
-
@smods_rec.pub_date.
|
47
|
+
expect(@smods_rec.pub_date).to eq('1886')
|
48
48
|
end
|
49
49
|
it 'should handle an s after the decade' do
|
50
50
|
m = "<mods #{@ns_decl}><originInfo>
|
@@ -52,89 +52,87 @@ describe "Date methods (searchworks.rb)" do
|
|
52
52
|
</originInfo></mods>"
|
53
53
|
@smods_rec = Stanford::Mods::Record.new
|
54
54
|
@smods_rec.from_str(m)
|
55
|
-
@smods_rec.pub_date.
|
55
|
+
expect(@smods_rec.pub_date).to eq('1890')
|
56
56
|
end
|
57
57
|
it 'should choose a date ending with CE if there are multiple dates' do
|
58
58
|
m = "<mods #{@ns_decl}><originInfo><dateIssued>7192 AM (li-Adam) / 1684 CE</dateIssued><issuance>monographic</issuance></originInfo>"
|
59
59
|
@smods_rec = Stanford::Mods::Record.new
|
60
60
|
@smods_rec.from_str(m)
|
61
|
-
@smods_rec.pub_date.
|
61
|
+
expect(@smods_rec.pub_date).to eq('1684')
|
62
62
|
end
|
63
63
|
it 'should handle hyphenated range dates' do
|
64
64
|
m = "<mods #{@ns_decl}><originInfo><dateIssued>1282 AH / 1865-6 CE</dateIssued><issuance>monographic</issuance></originInfo>"
|
65
65
|
@smods_rec = Stanford::Mods::Record.new
|
66
66
|
@smods_rec.from_str(m)
|
67
|
-
@smods_rec.pub_date.
|
67
|
+
expect(@smods_rec.pub_date).to eq('1865')
|
68
68
|
end
|
69
69
|
it 'should work with multiple 4 digit dates' do
|
70
70
|
m = "<mods #{@ns_decl}><originInfo><dateCreated>Text dated June 4, 1594; miniatures added by 1596</dateCreated></originInfo>"
|
71
71
|
@smods_rec = Stanford::Mods::Record.new
|
72
72
|
@smods_rec.from_str(m)
|
73
|
-
@smods_rec.pub_date.
|
73
|
+
expect(@smods_rec.pub_date).to eq('1594')
|
74
74
|
end
|
75
75
|
it 'should work on 3 digit BC dates' do
|
76
76
|
m = "<mods #{@ns_decl}><originInfo><dateCreated>300 B.C.</dateCreated></originInfo>"
|
77
77
|
@smods_rec = Stanford::Mods::Record.new
|
78
78
|
@smods_rec.from_str(m)
|
79
|
-
@smods_rec.pub_year.
|
80
|
-
@smods_rec.pub_date.
|
81
|
-
@smods_rec.pub_date_sort.
|
82
|
-
@smods_rec.pub_date_facet.
|
79
|
+
expect(@smods_rec.pub_year).to eq('-700')
|
80
|
+
expect(@smods_rec.pub_date).to eq('-700')
|
81
|
+
expect(@smods_rec.pub_date_sort).to eq('-700')
|
82
|
+
expect(@smods_rec.pub_date_facet).to eq('300 B.C.')
|
83
83
|
end
|
84
84
|
it 'should handle century based dates' do
|
85
85
|
m = "<mods #{@ns_decl}><originInfo><dateIssued>13th century AH / 19th CE</dateIssued><issuance>monographic</issuance></originInfo>"
|
86
86
|
@smods_rec = Stanford::Mods::Record.new
|
87
87
|
@smods_rec.from_str(m)
|
88
|
-
@smods_rec.pub_date_facet.
|
89
|
-
@smods_rec.pub_date_sort.
|
90
|
-
@smods_rec.pub_date.
|
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
91
|
end
|
92
92
|
it 'should handle multiple CE dates' do
|
93
93
|
m = "<mods #{@ns_decl}><originInfo><dateIssued>6 Dhu al-Hijjah 923 AH / 1517 CE -- 7 Rabi I 924 AH / 1518 CE</dateIssued><issuance>monographic</issuance></originInfo>"
|
94
94
|
@smods_rec = Stanford::Mods::Record.new
|
95
95
|
@smods_rec.from_str(m)
|
96
|
-
@smods_rec.pub_date.
|
97
|
-
@smods_rec.pub_date_sort.
|
98
|
-
@smods_rec.pub_date_facet.
|
96
|
+
expect(@smods_rec.pub_date).to eq('1517')
|
97
|
+
expect(@smods_rec.pub_date_sort).to eq('1517')
|
98
|
+
expect(@smods_rec.pub_date_facet).to eq('1517')
|
99
99
|
end
|
100
100
|
it 'should handle this case from walters' do
|
101
101
|
m = "<mods #{@ns_decl}><originInfo><dateIssued>Late 14th or early 15th century CE</dateIssued><issuance>monographic</issuance></originInfo>"
|
102
102
|
@smods_rec = Stanford::Mods::Record.new
|
103
103
|
@smods_rec.from_str(m)
|
104
|
-
@smods_rec.pub_date.
|
105
|
-
@smods_rec.pub_date_sort.
|
106
|
-
@smods_rec.pub_date_facet.
|
104
|
+
expect(@smods_rec.pub_date).to eq('14--')
|
105
|
+
expect(@smods_rec.pub_date_sort).to eq('1400')
|
106
|
+
expect(@smods_rec.pub_date_facet).to eq('15th century')
|
107
107
|
end
|
108
108
|
it 'should work on 3 digit dates' do
|
109
109
|
m = "<mods #{@ns_decl}><originInfo><dateIssued>966 CE</dateIssued><issuance>monographic</issuance></originInfo>"
|
110
110
|
@smods_rec = Stanford::Mods::Record.new
|
111
111
|
@smods_rec.from_str(m)
|
112
|
-
@smods_rec.pub_date.
|
113
|
-
@smods_rec.pub_date_sort.
|
114
|
-
@smods_rec.pub_date_facet.
|
112
|
+
expect(@smods_rec.pub_date).to eq('966')
|
113
|
+
expect(@smods_rec.pub_date_sort).to eq('0966')
|
114
|
+
expect(@smods_rec.pub_date_facet).to eq('966')
|
115
115
|
end
|
116
116
|
it 'should work on 3 digit dates' do
|
117
117
|
m = "<mods #{@ns_decl}><originInfo><dateIssued>3rd century AH / 9th CE</dateIssued><issuance>monographic</issuance></originInfo>"
|
118
118
|
@smods_rec = Stanford::Mods::Record.new
|
119
119
|
@smods_rec.from_str(m)
|
120
|
-
|
121
|
-
@smods_rec.
|
122
|
-
@smods_rec.
|
123
|
-
|
124
|
-
end
|
120
|
+
expect(@smods_rec.pub_date).to eq('8--')
|
121
|
+
expect(@smods_rec.pub_date_sort).to eq('0800')
|
122
|
+
expect(@smods_rec.pub_date_facet).to eq('9th century')
|
123
|
+
end
|
125
124
|
it 'should use the dateIssued without marc encoding for pub_date_display and the one with marc encoding for indexing, sorting and faceting' do
|
126
125
|
m = "<mods #{@ns_decl}><originInfo><dateIssued>[186-?]</dateIssued><dateIssued encoding=\"marc\">1860</dateIssued><issuance>monographic</issuance></originInfo>"
|
127
126
|
@smods_rec = Stanford::Mods::Record.new
|
128
127
|
@smods_rec.from_str(m)
|
129
|
-
|
130
|
-
@smods_rec.
|
131
|
-
@smods_rec.
|
132
|
-
@smods_rec.
|
133
|
-
@smods_rec.pub_date_facet.should == '1860'
|
128
|
+
expect(@smods_rec.pub_date_display).to eq('[186-?]')
|
129
|
+
expect(@smods_rec.pub_date).to eq('1860')
|
130
|
+
expect(@smods_rec.pub_date_sort).to eq('1860')
|
131
|
+
expect(@smods_rec.pub_date_facet).to eq('1860')
|
134
132
|
end
|
135
133
|
end # pub_date
|
136
134
|
|
137
|
-
context "dates with u notation (198u, 19uu)" do
|
135
|
+
context "dates with u notation (198u, 19uu)" do
|
138
136
|
context "single digit u notation (198u)" do
|
139
137
|
before(:all) do
|
140
138
|
m = "<mods #{@ns_decl}>
|
@@ -148,16 +146,16 @@ describe "Date methods (searchworks.rb)" do
|
|
148
146
|
it "get_u_year recognizes notation" do
|
149
147
|
dates = ["198u", "9999"]
|
150
148
|
uDate = @smods_rec.get_u_year dates
|
151
|
-
uDate.
|
149
|
+
expect(uDate).to eql("1980")
|
152
150
|
end
|
153
151
|
it 'pub_date: 198u = 1980' do
|
154
|
-
@smods_rec.pub_date.
|
152
|
+
expect(@smods_rec.pub_date).to eq('1980')
|
155
153
|
end
|
156
154
|
it "pub_date_sort: 198u = 1980" do
|
157
|
-
@smods_rec.pub_date_sort.
|
155
|
+
expect(@smods_rec.pub_date_sort).to eq('1980')
|
158
156
|
end
|
159
157
|
it "pub_date_facet: 198u = 1980" do
|
160
|
-
@smods_rec.pub_date_facet.
|
158
|
+
expect(@smods_rec.pub_date_facet).to eq('1980')
|
161
159
|
end
|
162
160
|
end
|
163
161
|
context "double digit u notation (19uu)" do
|
@@ -173,16 +171,16 @@ describe "Date methods (searchworks.rb)" do
|
|
173
171
|
it "get_u_year recognizes notation" do
|
174
172
|
dates = ["19uu", "9999"]
|
175
173
|
uDate = @smods_rec.get_u_year dates
|
176
|
-
uDate.
|
174
|
+
expect(uDate).to eql("19--")
|
177
175
|
end
|
178
176
|
it 'pub_date: 19uu = 19--' do
|
179
|
-
@smods_rec.pub_date.
|
177
|
+
expect(@smods_rec.pub_date).to eq('19--')
|
180
178
|
end
|
181
179
|
it "pub_date_sort: 19uu = 1900" do
|
182
|
-
@smods_rec.pub_date_sort.
|
180
|
+
expect(@smods_rec.pub_date_sort).to eq('1900')
|
183
181
|
end
|
184
182
|
it "pub_date_facet: 19uu = 20th century" do
|
185
|
-
@smods_rec.pub_date_facet.
|
183
|
+
expect(@smods_rec.pub_date_facet).to eq('20th century')
|
186
184
|
end
|
187
185
|
end
|
188
186
|
end # u notation
|
@@ -197,20 +195,20 @@ describe "Date methods (searchworks.rb)" do
|
|
197
195
|
@smods_rec.from_str(m)
|
198
196
|
end
|
199
197
|
it 'should work on normal dates' do
|
200
|
-
@smods_rec.
|
201
|
-
@smods_rec.pub_date_sort.
|
198
|
+
allow(@smods_rec).to receive(:pub_date).and_return('1945')
|
199
|
+
expect(@smods_rec.pub_date_sort).to eq('1945')
|
202
200
|
end
|
203
201
|
it 'should work on 3 digit dates' do
|
204
|
-
@smods_rec.
|
205
|
-
@smods_rec.pub_date_sort.
|
202
|
+
allow(@smods_rec).to receive(:pub_date).and_return('945')
|
203
|
+
expect(@smods_rec.pub_date_sort).to eq('0945')
|
206
204
|
end
|
207
205
|
it 'should work on century dates' do
|
208
|
-
@smods_rec.
|
209
|
-
@smods_rec.pub_date_sort.
|
206
|
+
allow(@smods_rec).to receive(:pub_date).and_return('16--')
|
207
|
+
expect(@smods_rec.pub_date_sort).to eq('1600')
|
210
208
|
end
|
211
209
|
it 'should work on 3 digit century dates' do
|
212
|
-
@smods_rec.
|
213
|
-
@smods_rec.pub_date_sort.
|
210
|
+
allow(@smods_rec).to receive(:pub_date).and_return('9--')
|
211
|
+
expect(@smods_rec.pub_date_sort).to eq('0900')
|
214
212
|
end
|
215
213
|
end
|
216
214
|
|
data/spec/searchworks_spec.rb
CHANGED
@@ -13,21 +13,21 @@ describe "Searchworks mixin for Stanford::Mods::Record" do
|
|
13
13
|
m = "<mods #{@ns_decl}><language><languageTerm authority='iso639-2b' type='code'>per ara, dut</languageTerm></language></mods>"
|
14
14
|
@smods_rec.from_str m
|
15
15
|
langs = @smods_rec.sw_language_facet
|
16
|
-
langs.size.
|
17
|
-
langs.
|
18
|
-
langs.
|
19
|
-
langs.
|
20
|
-
langs.
|
16
|
+
expect(langs.size).to eq(3)
|
17
|
+
expect(langs).to include("Persian")
|
18
|
+
expect(langs).to include("Arabic")
|
19
|
+
expect(langs).to include("Dutch")
|
20
|
+
expect(langs).not_to include("Dutch; Flemish")
|
21
21
|
end
|
22
22
|
it "should not have duplicates" do
|
23
23
|
m = "<mods #{@ns_decl}><language><languageTerm type='code' authority='iso639-2b'>eng</languageTerm><languageTerm type='text'>English</languageTerm></language></mods>"
|
24
24
|
@smods_rec.from_str m
|
25
25
|
langs = @smods_rec.sw_language_facet
|
26
|
-
langs.size.
|
27
|
-
langs.
|
28
|
-
end
|
26
|
+
expect(langs.size).to eq 1
|
27
|
+
expect(langs).to include "English"
|
28
|
+
end
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
context "sw author methods" do
|
32
32
|
before(:all) do
|
33
33
|
m = "<mods #{@ns_decl}><name type='personal'>
|
@@ -60,54 +60,54 @@ describe "Searchworks mixin for Stanford::Mods::Record" do
|
|
60
60
|
@smods_rec.from_str(m)
|
61
61
|
end
|
62
62
|
it "main author (for author_1xx_search)" do
|
63
|
-
@smods_rec.
|
63
|
+
expect(@smods_rec).to receive(:main_author_w_date) # in stanford-mods.rb
|
64
64
|
@smods_rec.sw_main_author
|
65
65
|
end
|
66
66
|
it "additional authors (for author_7xx_search)" do
|
67
|
-
@smods_rec.
|
67
|
+
expect(@smods_rec).to receive(:additional_authors_w_dates) # in stanford-mods.rb
|
68
68
|
@smods_rec.sw_addl_authors
|
69
69
|
end
|
70
70
|
it "person authors (for author_person_facet, author_person_display)" do
|
71
|
-
@smods_rec.
|
71
|
+
expect(@smods_rec).to receive(:personal_names_w_dates) # in Mods gem
|
72
72
|
@smods_rec.sw_person_authors
|
73
73
|
end
|
74
74
|
it "non-person authors (for author_other_facet)" do
|
75
|
-
@smods_rec.sw_impersonal_authors.
|
75
|
+
expect(@smods_rec.sw_impersonal_authors).to eq(['Watchful Eye, 1850-', 'Exciting Prints', 'plain', 'conference', 'family'])
|
76
76
|
end
|
77
77
|
it "corporate authors (for author_corp_display)" do
|
78
|
-
@smods_rec.sw_corporate_authors.
|
78
|
+
expect(@smods_rec.sw_corporate_authors).to eq(['Watchful Eye, 1850-', 'Exciting Prints'])
|
79
79
|
end
|
80
80
|
it "meeting authors (for author_meeting_display)" do
|
81
|
-
@smods_rec.sw_meeting_authors.
|
82
|
-
end
|
81
|
+
expect(@smods_rec.sw_meeting_authors).to eq(['conference'])
|
82
|
+
end
|
83
83
|
context "sort author" do
|
84
84
|
it "should be a String" do
|
85
|
-
@smods_rec.sw_sort_author.
|
85
|
+
expect(@smods_rec.sw_sort_author).to eq('qJerk')
|
86
86
|
end
|
87
87
|
it "should include the main author, as retrieved by :main_author_w_date" do
|
88
|
-
@smods_rec.
|
88
|
+
expect(@smods_rec).to receive(:main_author_w_date) # in stanford-mods.rb
|
89
89
|
@smods_rec.sw_sort_author
|
90
90
|
end
|
91
91
|
it "should append the sort title, as retrieved by :sort_title" do
|
92
|
-
@smods_rec.
|
92
|
+
expect(@smods_rec).to receive(:sort_title) # in Mods gem
|
93
93
|
@smods_rec.sw_sort_author
|
94
94
|
end
|
95
95
|
it "should not begin or end with whitespace" do
|
96
|
-
@smods_rec.sw_sort_author.
|
96
|
+
expect(@smods_rec.sw_sort_author).to eq(@smods_rec.sw_sort_author.strip)
|
97
97
|
end
|
98
98
|
it "should substitute the java Character.MAX_CODE_POINT for nil main_author so missing main authors sort last" do
|
99
99
|
r = Stanford::Mods::Record.new
|
100
100
|
r.from_str "<mods #{@ns_decl}><titleInfo><title>Jerk</title></titleInfo></mods>"
|
101
|
-
r.sw_sort_author.
|
102
|
-
r.sw_sort_author.
|
103
|
-
r.sw_sort_author.
|
101
|
+
expect(r.sw_sort_author).to match(/ Jerk$/)
|
102
|
+
expect(r.sw_sort_author).to match("\u{10FFFF}")
|
103
|
+
expect(r.sw_sort_author).to match("\xF4\x8F\xBF\xBF")
|
104
104
|
end
|
105
105
|
it "should not have any punctuation marks" do
|
106
106
|
r = Stanford::Mods::Record.new
|
107
107
|
r.from_str "<mods #{@ns_decl}><titleInfo><title>J,e.r;;;k</title></titleInfo></mods>"
|
108
|
-
r.sw_sort_author.
|
108
|
+
expect(r.sw_sort_author).to match(/ Jerk$/)
|
109
109
|
end
|
110
110
|
end
|
111
111
|
end # context sw author methods
|
112
112
|
|
113
|
-
end
|
113
|
+
end
|