pennmarc 1.0.15 → 1.0.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pennmarc/heading_control.rb +1 -1
- data/lib/pennmarc/helpers/access.rb +5 -4
- data/lib/pennmarc/helpers/format.rb +4 -1
- data/lib/pennmarc/helpers/location.rb +65 -23
- data/lib/pennmarc/helpers/note.rb +8 -1
- data/lib/pennmarc/helpers/subject.rb +23 -7
- data/lib/pennmarc/mappers.rb +5 -0
- data/lib/pennmarc/mappings/location_overrides.yml +5 -0
- data/lib/pennmarc/mappings/locations.yml +101 -1
- data/lib/pennmarc/util.rb +17 -7
- data/lib/pennmarc/version.rb +1 -1
- data/spec/lib/pennmarc/helpers/format_spec.rb +14 -0
- data/spec/lib/pennmarc/helpers/location_spec.rb +16 -0
- data/spec/lib/pennmarc/helpers/note_spec.rb +18 -0
- data/spec/lib/pennmarc/helpers/subject_spec.rb +54 -22
- data/spec/support/marc_spec_helpers.rb +5 -4
- metadata +3 -2
data/lib/pennmarc/util.rb
CHANGED
@@ -5,6 +5,13 @@ require_relative 'heading_control'
|
|
5
5
|
module PennMARC
|
6
6
|
# class to hold "utility" methods used in MARC parsing methods
|
7
7
|
module Util
|
8
|
+
TRAILING_PUNCTUATIONS_PATTERNS = { semicolon: /\s*;\s*$/,
|
9
|
+
colon: /\s*:\s*$/,
|
10
|
+
equal: /=$/,
|
11
|
+
slash: %r{\s*/\s*$},
|
12
|
+
comma: /\s*,\s*$/,
|
13
|
+
period: /\.\s*$/ }.freeze # TODO: revise to exclude "etc."
|
14
|
+
|
8
15
|
# Check if a given record has a field present by tag (e.g., '041')
|
9
16
|
# @param [MARC::Record] record
|
10
17
|
# @param [String] marc_field
|
@@ -115,14 +122,17 @@ module PennMARC
|
|
115
122
|
|
116
123
|
# @param [Symbol|String] trailer to target for removal
|
117
124
|
# @param [String] string to modify
|
125
|
+
# @return [String]
|
118
126
|
def trim_trailing(trailer, string)
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
127
|
+
string.sub TRAILING_PUNCTUATIONS_PATTERNS[trailer.to_sym], ''
|
128
|
+
end
|
129
|
+
|
130
|
+
# trim trailing punctuation, manipulating string in place
|
131
|
+
# @param [Symbol|String] trailer to target for removal
|
132
|
+
# @param [String] string to modify
|
133
|
+
# @return [String, Nil] string to modify
|
134
|
+
def trim_trailing!(trailer, string)
|
135
|
+
string.sub! TRAILING_PUNCTUATIONS_PATTERNS[trailer.to_sym], ''
|
126
136
|
end
|
127
137
|
|
128
138
|
# Intelligently append given punctuation to the end of a string
|
data/lib/pennmarc/version.rb
CHANGED
@@ -181,6 +181,20 @@ describe 'PennMARC::Format' do
|
|
181
181
|
expect(value.join(' ')).not_to include 'excluded'
|
182
182
|
end
|
183
183
|
end
|
184
|
+
|
185
|
+
context 'with an unrelated linked alternate' do
|
186
|
+
let(:fields) do
|
187
|
+
[marc_field(tag: '300', subfields: { a: '96 pages ;', c: '23 cm ' }),
|
188
|
+
marc_field(tag: '880', subfields: { '6': '700', a: 'Schweizer, Shlomo,', d: '1903-',
|
189
|
+
'0': 'https://id.loc.gov/authorities/names/no95018724' })]
|
190
|
+
end
|
191
|
+
|
192
|
+
it 'returns the expected format values' do
|
193
|
+
value = helper.show(record)
|
194
|
+
expect(value).to contain_exactly '96 pages ; 23 cm'
|
195
|
+
expect(value.join(' ')).not_to include 'https://id.loc.gov/authorities/names/no95018724'
|
196
|
+
end
|
197
|
+
end
|
184
198
|
end
|
185
199
|
|
186
200
|
describe '.other_show' do
|
@@ -111,4 +111,20 @@ describe 'PennMARC::Location' do
|
|
111
111
|
end
|
112
112
|
end
|
113
113
|
end
|
114
|
+
|
115
|
+
context 'with a specific location override' do
|
116
|
+
let(:record) do
|
117
|
+
marc_record(fields: [marc_field(tag: enriched_marc::Pub::ITEM_TAG,
|
118
|
+
subfields: { enriched_marc::Pub::ITEM_CURRENT_LOCATION => 'vanp',
|
119
|
+
enriched_marc::Pub::ITEM_CALL_NUMBER => 'ML3534 .D85 1984' }),
|
120
|
+
marc_field(tag: enriched_marc::Pub::ITEM_TAG,
|
121
|
+
subfields: { enriched_marc::Pub::ITEM_CURRENT_LOCATION => 'stor',
|
122
|
+
enriched_marc::Pub::ITEM_CALL_NUMBER => 'L3534 .D85 1984' })])
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'returns expected values' do
|
126
|
+
expect(helper.location(record: record, display_value: :specific_location, location_map: mapping))
|
127
|
+
.to(contain_exactly(PennMARC::Mappers.location_overrides[:albrecht][:specific_location], 'LIBRA'))
|
128
|
+
end
|
129
|
+
end
|
114
130
|
end
|
@@ -296,5 +296,23 @@ text for URI http://www.universal.resource/locator'.squish,
|
|
296
296
|
)
|
297
297
|
end
|
298
298
|
end
|
299
|
+
|
300
|
+
describe '.bound_with_show' do
|
301
|
+
let(:record) { marc_record(fields: fields) }
|
302
|
+
|
303
|
+
let(:fields) do
|
304
|
+
[
|
305
|
+
marc_field(tag: '501', subfields: { a: 'With: Peer Gynt (Suite) no. 1-2 / Edvard Grieg' }),
|
306
|
+
marc_field(tag: '501', subfields: { a: 'With: Schumann, C. Romances, piano, op. 11. No. 2' })
|
307
|
+
]
|
308
|
+
end
|
309
|
+
|
310
|
+
let(:values) { helper.bound_with_show(record) }
|
311
|
+
|
312
|
+
it 'returns expected values' do
|
313
|
+
expect(values).to contain_exactly('With: Peer Gynt (Suite) no. 1-2 / Edvard Grieg',
|
314
|
+
'With: Schumann, C. Romances, piano, op. 11. No. 2')
|
315
|
+
end
|
316
|
+
end
|
299
317
|
end
|
300
318
|
end
|
@@ -101,7 +101,7 @@ describe 'PennMARC::Subject' do
|
|
101
101
|
let(:fields) do
|
102
102
|
[marc_field(tag: '650', indicator2: '7',
|
103
103
|
subfields: {
|
104
|
-
a: 'Libraries', d: '22nd Century', x: 'History', e: 'relator',
|
104
|
+
a: 'Libraries,', d: '22nd Century,', x: 'History.', e: 'relator',
|
105
105
|
'2': 'fast', '0': 'http://fast.org/libraries'
|
106
106
|
})]
|
107
107
|
end
|
@@ -127,6 +127,21 @@ describe 'PennMARC::Subject' do
|
|
127
127
|
expect(values.first).to eq 'Libraries, 22nd Century--History'
|
128
128
|
end
|
129
129
|
end
|
130
|
+
|
131
|
+
context 'with a record with trailing periods' do
|
132
|
+
let(:fields) do
|
133
|
+
[marc_field(tag: '600', indicator2: '0',
|
134
|
+
subfields: {
|
135
|
+
a: 'R.G.', q: '(Robert Gordon).',
|
136
|
+
t: 'Spiritual order and Christian liberty proved to be consistent in the Churches of Christ. '
|
137
|
+
})]
|
138
|
+
end
|
139
|
+
|
140
|
+
it 'drops the final trailing period' do
|
141
|
+
expect(values).to contain_exactly('R.G. (Robert Gordon). Spiritual order and Christian liberty proved ' \
|
142
|
+
'to be consistent in the Churches of Christ')
|
143
|
+
end
|
144
|
+
end
|
130
145
|
end
|
131
146
|
|
132
147
|
describe '.show' do
|
@@ -146,8 +161,8 @@ describe 'PennMARC::Subject' do
|
|
146
161
|
end
|
147
162
|
|
148
163
|
it 'shows all valid subject headings without duplicates' do
|
149
|
-
expect(helper.show(record)).to contain_exactly('Nephrology--Periodicals', 'Nephrology', 'Kidney Diseases',
|
150
|
-
'Local Heading')
|
164
|
+
expect(helper.show(record)).to contain_exactly('Nephrology--Periodicals.', 'Nephrology.', 'Kidney Diseases.',
|
165
|
+
'Local Heading.')
|
151
166
|
end
|
152
167
|
end
|
153
168
|
|
@@ -155,7 +170,7 @@ describe 'PennMARC::Subject' do
|
|
155
170
|
let(:fields) do
|
156
171
|
[marc_field(tag: '650', indicator2: '0', subfields: {
|
157
172
|
a: 'Subways',
|
158
|
-
z: ['Pennsylvania', 'Philadelphia Metropolitan Area'],
|
173
|
+
z: ['Pennsylvania,', 'Philadelphia Metropolitan Area,'],
|
159
174
|
v: 'Maps',
|
160
175
|
y: '1989',
|
161
176
|
e: 'relator'
|
@@ -163,7 +178,7 @@ describe 'PennMARC::Subject' do
|
|
163
178
|
end
|
164
179
|
|
165
180
|
it 'properly formats the heading parts' do
|
166
|
-
expect(values.first).to eq 'Subways--Pennsylvania--Philadelphia Metropolitan Area--Maps--1989 relator'
|
181
|
+
expect(values.first).to eq 'Subways--Pennsylvania--Philadelphia Metropolitan Area--Maps--1989 relator.'
|
167
182
|
end
|
168
183
|
end
|
169
184
|
|
@@ -171,20 +186,37 @@ describe 'PennMARC::Subject' do
|
|
171
186
|
let(:fields) do
|
172
187
|
[marc_field(tag: '600', indicator2: '7', subfields: {
|
173
188
|
a: 'Franklin, Benjamin,',
|
174
|
-
d: '1706-1790',
|
189
|
+
d: '1706-1790.',
|
175
190
|
'2': 'fast',
|
176
191
|
'0': 'http://id.worldcat.org/fast/34115'
|
177
192
|
}),
|
178
193
|
marc_field(tag: '600', indicator1: '1', indicator2: '0', subfields: {
|
179
194
|
a: 'Franklin, Benjamin,',
|
180
|
-
d: '1706-1790
|
195
|
+
d: '1706-1790',
|
181
196
|
x: 'As inventor.'
|
197
|
+
}),
|
198
|
+
marc_field(tag: '650', indicator1: '1', indicator2: '0', subfields: {
|
199
|
+
a: 'Franklin stoves.'
|
182
200
|
})]
|
183
201
|
end
|
184
202
|
|
185
|
-
it '
|
203
|
+
it 'properly handles punctuation in subject parts' do
|
186
204
|
expect(values).to contain_exactly 'Franklin, Benjamin, 1706-1790.',
|
187
|
-
'Franklin, Benjamin, 1706-1790--As inventor.'
|
205
|
+
'Franklin, Benjamin, 1706-1790--As inventor.', 'Franklin stoves.'
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
context 'with a record without trailing period in last subject part' do
|
210
|
+
let(:fields) do
|
211
|
+
[marc_field(tag: '651', indicator2: '7',
|
212
|
+
subfields: {
|
213
|
+
a: 'New York State (State)', z: 'New York', '2': 'fast', '0': '(OCoLC)fst01204333',
|
214
|
+
'1': 'https://id.oclc.org/worldcat/entity/E39QbtfRvQh7864Jh4rDGBFDWc'
|
215
|
+
})]
|
216
|
+
end
|
217
|
+
|
218
|
+
it 'adds a trailing period' do
|
219
|
+
expect(values).to contain_exactly('New York State (State)--New York.')
|
188
220
|
end
|
189
221
|
end
|
190
222
|
|
@@ -200,40 +232,40 @@ describe 'PennMARC::Subject' do
|
|
200
232
|
end
|
201
233
|
|
202
234
|
it 'properly formats the heading parts' do
|
203
|
-
expect(values.first).to eq 'Chicago (Ill.)--Moral conditions--Church minutes--1875-1878'
|
235
|
+
expect(values.first).to eq 'Chicago (Ill.)--Moral conditions--Church minutes--1875-1878.'
|
204
236
|
end
|
205
237
|
end
|
206
238
|
|
207
239
|
context 'with a robust 611 heading including many subfields' do
|
208
240
|
let(:fields) do
|
209
241
|
[marc_field(tag: '611', indicator2: '0', subfields: {
|
210
|
-
a: 'Conference',
|
211
|
-
c: ['(Johannesburg, South Africa', 'Cape Town, South Africa'],
|
242
|
+
a: 'Conference,',
|
243
|
+
c: ['(Johannesburg, South Africa,', 'Cape Town, South Africa,'],
|
212
244
|
d: '2002)',
|
213
245
|
n: '2nd'
|
214
246
|
})]
|
215
247
|
end
|
216
248
|
|
217
249
|
it 'properly formats the heading parts' do
|
218
|
-
expect(values.first).to eq 'Conference, (Johannesburg, South Africa, Cape Town, South Africa, 2002)--2nd'
|
250
|
+
expect(values.first).to eq 'Conference, (Johannesburg, South Africa, Cape Town, South Africa, 2002)--2nd.'
|
219
251
|
end
|
220
252
|
end
|
221
253
|
|
222
254
|
context 'with a robust 600 heading including many subfields' do
|
223
255
|
let(:fields) do
|
224
256
|
[marc_field(tag: '600', indicator2: '0', subfields: {
|
225
|
-
a: 'Person, Significant Author',
|
226
|
-
b: 'Numerator',
|
227
|
-
c:
|
228
|
-
d: '1899-1971',
|
257
|
+
a: 'Person, Significant Author,',
|
258
|
+
b: 'Numerator,',
|
259
|
+
c: ['Title,', 'Rank,'],
|
260
|
+
d: '1899-1971,',
|
229
261
|
t: 'Collection',
|
230
|
-
v: 'Early works to 1950'
|
262
|
+
v: 'Early works to 1950.'
|
231
263
|
})]
|
232
264
|
end
|
233
265
|
|
234
266
|
it 'properly formats the heading parts' do
|
235
267
|
expect(values.first).to eq('Person, Significant Author, Numerator, Title, Rank, 1899-1971, Collection--' \
|
236
|
-
'Early works to 1950')
|
268
|
+
'Early works to 1950.')
|
237
269
|
end
|
238
270
|
end
|
239
271
|
end
|
@@ -249,7 +281,7 @@ describe 'PennMARC::Subject' do
|
|
249
281
|
let(:values) { helper.childrens_show(record) }
|
250
282
|
|
251
283
|
it 'includes heading terms only from subject tags with an indicator 2 of "1"' do
|
252
|
-
expect(values).to contain_exactly 'Frogs--Fiction', 'Toads--Fiction'
|
284
|
+
expect(values).to contain_exactly 'Frogs--Fiction.', 'Toads--Fiction.'
|
253
285
|
end
|
254
286
|
end
|
255
287
|
|
@@ -267,7 +299,7 @@ describe 'PennMARC::Subject' do
|
|
267
299
|
end
|
268
300
|
|
269
301
|
it 'includes heading terms only from subject tags with indicator 2 of "2"' do
|
270
|
-
expect(helper.medical_show(record)).to contain_exactly 'Nephrology'
|
302
|
+
expect(helper.medical_show(record)).to contain_exactly 'Nephrology.'
|
271
303
|
end
|
272
304
|
end
|
273
305
|
|
@@ -280,7 +312,7 @@ describe 'PennMARC::Subject' do
|
|
280
312
|
end
|
281
313
|
|
282
314
|
it 'includes heading terms only from subject tags with indicator 2 of "4" or in the 69X range' do
|
283
|
-
expect(helper.local_show(record)).to contain_exactly 'Local--Heading', 'Super Local.'
|
315
|
+
expect(helper.local_show(record)).to contain_exactly 'Local--Heading.', 'Super Local.'
|
284
316
|
end
|
285
317
|
end
|
286
318
|
end
|
@@ -72,13 +72,14 @@ module MarcSpecHelpers
|
|
72
72
|
# location_map[:stor][:library] #=> 'LIBRA'
|
73
73
|
# @return [Hash]
|
74
74
|
def location_map
|
75
|
-
{
|
76
|
-
dent: { specific_location: 'Levy Dental Medicine Library - Stacks',
|
75
|
+
{ dent: { specific_location: 'Levy Dental Medicine Library - Stacks',
|
77
76
|
library: ['Health Sciences Libraries', 'Levy Dental Medicine Library'],
|
78
77
|
display: 'Levy Dental Medicine Library - Stacks' },
|
79
78
|
stor: { specific_location: 'LIBRA',
|
80
79
|
library: 'LIBRA',
|
81
|
-
display: 'LIBRA' }
|
82
|
-
|
80
|
+
display: 'LIBRA' },
|
81
|
+
vanp: { specific_location: 'Van Pelt - Stacks',
|
82
|
+
library: 'Van Pelt-Dietrich Library Center',
|
83
|
+
display: 'Van Pelt Library' } }
|
83
84
|
end
|
84
85
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pennmarc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Kanning
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2024-
|
13
|
+
date: 2024-04-12 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
@@ -119,6 +119,7 @@ files:
|
|
119
119
|
- lib/pennmarc/mappings/iso639-2-languages.yml
|
120
120
|
- lib/pennmarc/mappings/iso639-3-languages.yml
|
121
121
|
- lib/pennmarc/mappings/loc_classification.yml
|
122
|
+
- lib/pennmarc/mappings/location_overrides.yml
|
122
123
|
- lib/pennmarc/mappings/locations.yml
|
123
124
|
- lib/pennmarc/mappings/relator.yml
|
124
125
|
- lib/pennmarc/parser.rb
|