stanford-mods 2.2.1 → 2.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/stanford-mods/searchworks.rb +34 -24
- data/lib/stanford-mods/version.rb +1 -1
- data/spec/searchworks_spec.rb +43 -0
- data/spec/searchworks_title_spec.rb +11 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d876e2b5f5ab556e1140c7846fe5a6b23bdc3163
|
4
|
+
data.tar.gz: 4c150486603f2ae953ed0ee7546502cbc2ab1ea2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9416188a4effed446e89fc9474996d02e2c0d9ab167ac80dd7ec960a83e3973edadb67ec9698d2db8bcf52b1ec594e3267542fdd057e0df51759d3ceb21c97b8
|
7
|
+
data.tar.gz: 1ee250dcef68b1ac7239d241977cb18e41b76dcd03df8e7e6df756a412f81670d2ca0d2d9d2b1a478e21ba5f0862993a43c48019de24dd46bf69a25531007284
|
@@ -27,19 +27,18 @@ module Stanford
|
|
27
27
|
# get languageTerm codes and add their translations to the result
|
28
28
|
n.code_term.each { |ct|
|
29
29
|
if ct.authority =~ /^iso639/
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
vals = ct.text.split(/[,|\ ]/).reject { |x| x.strip.empty? }
|
31
|
+
vals.each do |v|
|
32
|
+
if ISO_639.find(v.strip)
|
33
33
|
iso639_val = ISO_639.find(v.strip).english_name
|
34
34
|
if SEARCHWORKS_LANGUAGES.has_value?(iso639_val)
|
35
35
|
result << iso639_val
|
36
36
|
else
|
37
37
|
result << SEARCHWORKS_LANGUAGES[v.strip]
|
38
38
|
end
|
39
|
+
else
|
40
|
+
logger.warn "Couldn't find english name for #{ct.text}"
|
39
41
|
end
|
40
|
-
rescue
|
41
|
-
# TODO: this should be written to a logger
|
42
|
-
p "Couldn't find english name for #{ct.text}"
|
43
42
|
end
|
44
43
|
else
|
45
44
|
vals = ct.text.split(/[,|\ ]/).reject { |x| x.strip.empty? }
|
@@ -127,25 +126,42 @@ module Stanford
|
|
127
126
|
|
128
127
|
# @return [String] value for title_245a_search field
|
129
128
|
def sw_short_title
|
130
|
-
short_titles ? short_titles.first : nil
|
129
|
+
short_titles ? short_titles.compact.reject(&:empty?).first : nil
|
130
|
+
end
|
131
|
+
|
132
|
+
# @return [Nokogiri::XML::NodeSet] title_info nodes, rejecting ones that just have blank text values
|
133
|
+
def present_title_info_nodes
|
134
|
+
mods_ng_xml.title_info.reject {|node| node.text.strip.empty?}
|
135
|
+
end
|
136
|
+
|
137
|
+
# @return [Nokogiri::XML::Node] the first titleInfo node if present, else nil
|
138
|
+
def first_title_info_node
|
139
|
+
present_title_info_nodes ? present_title_info_nodes.first : nil
|
131
140
|
end
|
132
141
|
|
142
|
+
# @return [String] the nonSort text portion of the titleInfo node as a string (if non-empty, else nil)
|
143
|
+
def nonSort_title
|
144
|
+
first_title_info_node.nonSort.text.strip.empty? ? nil : first_title_info_node.nonSort.text.strip
|
145
|
+
end
|
146
|
+
|
147
|
+
# @return [String] the text of the titleInfo node as a string (if non-empty, else nil)
|
148
|
+
def title
|
149
|
+
first_title_info_node.title.text.strip.empty? ? nil : first_title_info_node.title.text.strip
|
150
|
+
end
|
151
|
+
|
133
152
|
# @return [String] value for title_245_search, title_full_display
|
134
153
|
def sw_full_title
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
nonSort = outer_node.nonSort.text.strip.empty? ? nil : outer_node.nonSort.text.strip
|
139
|
-
title = outer_node.title.text.strip.empty? ? nil : outer_node.title.text.strip
|
140
|
-
preSubTitle = nonSort ? [nonSort, title].compact.join(" ") : title
|
154
|
+
|
155
|
+
return nil unless first_title_info_node
|
156
|
+
preSubTitle = nonSort_title ? [nonSort_title, title].compact.join(" ") : title
|
141
157
|
preSubTitle.sub!(/:$/, '') if preSubTitle # remove trailing colon
|
142
158
|
|
143
|
-
subTitle =
|
159
|
+
subTitle = first_title_info_node.subTitle.text.strip
|
144
160
|
preParts = subTitle.empty? ? preSubTitle : preSubTitle + " : " + subTitle
|
145
161
|
preParts.sub!(/\.$/, '') if preParts # remove trailing period
|
146
162
|
|
147
|
-
partName =
|
148
|
-
partNumber =
|
163
|
+
partName = first_title_info_node.partName.text.strip unless first_title_info_node.partName.text.strip.empty?
|
164
|
+
partNumber = first_title_info_node.partNumber.text.strip unless first_title_info_node.partNumber.text.strip.empty?
|
149
165
|
partNumber.sub!(/,$/, '') if partNumber # remove trailing comma
|
150
166
|
if partNumber && partName
|
151
167
|
parts = partNumber + ", " + partName
|
@@ -157,6 +173,7 @@ module Stanford
|
|
157
173
|
parts.sub!(/\.$/, '') if parts
|
158
174
|
|
159
175
|
result = parts ? preParts + ". " + parts : preParts
|
176
|
+
return nil unless result
|
160
177
|
result += "." unless result =~ /[[:punct:]]$/
|
161
178
|
result.strip!
|
162
179
|
result = nil if result.empty?
|
@@ -182,15 +199,8 @@ module Stanford
|
|
182
199
|
# Returns a sortable version of the main title
|
183
200
|
# @return [String] value for title_sort field
|
184
201
|
def sw_sort_title
|
185
|
-
# get nonSort piece
|
186
|
-
outer_nodes = mods_ng_xml.title_info
|
187
|
-
outer_node = outer_nodes ? outer_nodes.first : nil
|
188
|
-
if outer_node
|
189
|
-
nonSort = outer_node.nonSort.text.strip.empty? ? nil : outer_node.nonSort.text.strip
|
190
|
-
end
|
191
|
-
|
192
202
|
val = '' + (sw_full_title ? sw_full_title : '')
|
193
|
-
val.sub!(Regexp.new("^" + Regexp.escape(
|
203
|
+
val.sub!(Regexp.new("^" + Regexp.escape(nonSort_title)), '') if nonSort_title
|
194
204
|
val.gsub!(/[[:punct:]]*/, '').strip
|
195
205
|
val.squeeze(" ").strip
|
196
206
|
end
|
data/spec/searchworks_spec.rb
CHANGED
@@ -13,7 +13,50 @@ describe "Searchworks mixin for Stanford::Mods::Record" do
|
|
13
13
|
expect(langs.size).to eq(3)
|
14
14
|
expect(langs).to include("Persian", "Arabic", "Dutch")
|
15
15
|
expect(langs).not_to include("Dutch; Flemish")
|
16
|
+
end
|
17
|
+
it "should return a language string from lookup for a valid language code that has a type=code specified but no authority" do
|
18
|
+
m = "<mods #{@ns_decl}> <language><languageTerm type='code'>eng</languageTerm></language></mods>"
|
19
|
+
@smods_rec.from_str m
|
20
|
+
langs = @smods_rec.sw_language_facet
|
21
|
+
expect(langs.size).to eq(1)
|
22
|
+
expect(langs).to eq ["English"]
|
23
|
+
expect(langs).not_to include("eng")
|
24
|
+
end
|
25
|
+
it "should return nil for a language code that has a type=code specified but no authority" do
|
26
|
+
m = "<mods #{@ns_decl}> <language><languageTerm type='code'>bogus</languageTerm></language></mods>"
|
27
|
+
@smods_rec.from_str m
|
28
|
+
langs = @smods_rec.sw_language_facet
|
29
|
+
expect(langs.size).to be 1
|
30
|
+
expect(langs).to eq [nil]
|
16
31
|
end
|
32
|
+
it "should return nothing when the authority and type=code are specified but the language code cannot be found" do
|
33
|
+
m = "<mods #{@ns_decl}><language><languageTerm authority='iso639-2b' type='code'>bogus</languageTerm></language></mods>"
|
34
|
+
@smods_rec.from_str m
|
35
|
+
expect(@smods_rec.logger).to receive(:warn).with(/Couldn't find english name for bogus/)
|
36
|
+
langs = @smods_rec.sw_language_facet
|
37
|
+
expect(langs.size).to eq(0)
|
38
|
+
end
|
39
|
+
it "should return nothing for a language code that has no authority or type specified" do
|
40
|
+
m = "<mods #{@ns_decl}> <language><languageTerm>bogus</languageTerm></language></mods>"
|
41
|
+
@smods_rec.from_str m
|
42
|
+
langs = @smods_rec.sw_language_facet
|
43
|
+
expect(langs.size).to be 0
|
44
|
+
expect(langs).to eq []
|
45
|
+
end
|
46
|
+
it "should return nothing for a language code that has an unknown authority and doesn't have a type specified" do
|
47
|
+
m = "<mods #{@ns_decl}> <language><languageTerm authority='bogus-authority'>bogus</languageTerm></language></mods>"
|
48
|
+
@smods_rec.from_str m
|
49
|
+
langs = @smods_rec.sw_language_facet
|
50
|
+
expect(langs.size).to be 0
|
51
|
+
expect(langs).to eq []
|
52
|
+
end
|
53
|
+
it "should return nothing for a blank languageTerm node (even when the authority is valid)" do
|
54
|
+
m = "<mods #{@ns_decl}> <language><languageTerm authority='iso639-2b' type='code'></languageTerm></language></mods>"
|
55
|
+
@smods_rec.from_str m
|
56
|
+
langs = @smods_rec.sw_language_facet
|
57
|
+
expect(langs.size).to be 0
|
58
|
+
expect(langs).to eq []
|
59
|
+
end
|
17
60
|
it "should not have duplicates" do
|
18
61
|
m = "<mods #{@ns_decl}><language><languageTerm type='code' authority='iso639-2b'>eng</languageTerm><languageTerm type='text'>English</languageTerm></language></mods>"
|
19
62
|
@smods_rec.from_str m
|
@@ -7,7 +7,7 @@ describe 'title fields (searchworks.rb)' do
|
|
7
7
|
@smods_rec.from_str m
|
8
8
|
end
|
9
9
|
|
10
|
-
context 'short title (for title_245a_search, title_245a_display)
|
10
|
+
context 'short title (for title_245a_search, title_245a_display)' do
|
11
11
|
it 'should call :short_titles' do
|
12
12
|
expect(@smods_rec).to receive(:short_titles) # in Mods gem
|
13
13
|
@smods_rec.sw_short_title
|
@@ -17,6 +17,16 @@ describe 'title fields (searchworks.rb)' do
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
+
context 'blank title node' do
|
21
|
+
it 'should deal with a second blank titleInfo node' do
|
22
|
+
m = "<mods #{@ns_decl}><titleInfo> </titleInfo><otherStuff>goes here</otherStuff><titleInfo><title>Jerk</title><subTitle>A Tale of Tourettes</subTitle><nonSort>The</nonSort></titleInfo></mods>"
|
23
|
+
smods_rec_blank_node = Stanford::Mods::Record.new
|
24
|
+
smods_rec_blank_node.from_str m
|
25
|
+
expect(smods_rec_blank_node.sw_short_title).to eq 'The Jerk'
|
26
|
+
expect(smods_rec_blank_node.sw_full_title).to eq 'The Jerk : A Tale of Tourettes.'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
20
30
|
context 'full title (for title_245_search, title_full_display)' do
|
21
31
|
it 'should be a String' do
|
22
32
|
expect(@smods_rec.sw_full_title).to eq 'The Jerk : A Tale of Tourettes.'
|
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: 2.2.
|
4
|
+
version: 2.2.2
|
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: 2016-
|
12
|
+
date: 2016-09-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mods
|
@@ -171,7 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
171
171
|
version: '0'
|
172
172
|
requirements: []
|
173
173
|
rubyforge_project:
|
174
|
-
rubygems_version: 2.4.
|
174
|
+
rubygems_version: 2.4.5.1
|
175
175
|
signing_key:
|
176
176
|
specification_version: 4
|
177
177
|
summary: Stanford specific wrangling of MODS metadata
|
@@ -195,3 +195,4 @@ test_files:
|
|
195
195
|
- spec/searchworks_title_spec.rb
|
196
196
|
- spec/spec_helper.rb
|
197
197
|
- spec/sw_publication_spec.rb
|
198
|
+
has_rdoc:
|