pennmarc 1.0.18 → 1.0.20

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,31 +6,36 @@ describe 'PennMARC::Format' do
6
6
  let(:helper) { PennMARC::Format }
7
7
 
8
8
  describe '.facet' do
9
- let(:map) { location_map }
10
- let(:formats) { helper.facet(record, location_map: map) }
9
+ let(:formats) { helper.facet(record) }
11
10
 
12
11
  context 'with an "Archive"' do
13
- let(:map) do
14
- { musearch: { specific_location: 'Penn Museum Archives',
15
- library: 'Penn Museum Archives',
16
- display: 'Penn Museum Archives, 215-898-8304' },
17
- nursarch: { specific_location: 'Nursing Archives',
18
- library: 'Nursing Archives',
19
- display: 'Barbara Bates Center for History of Nursing - Fagin Hall 2U' } }
12
+ context 'with an 852 field' do
13
+ let(:record) do
14
+ marc_record fields: [marc_field(tag: '852', subfields: { c: 'archarch' })]
15
+ end
16
+
17
+ it 'returns format values of "Archive"' do
18
+ expect(formats).to include 'Archive'
19
+ end
20
20
  end
21
21
 
22
- context 'with a record in "Penn Museum Archives (musearch)"' do
23
- let(:record) { marc_record fields: [marc_field(tag: 'hld', subfields: { c: 'musearch' })] }
22
+ context 'with publishing enriched fields' do
23
+ let(:record) do
24
+ marc_record fields: [marc_field(tag: PennMARC::Enriched::Pub::ITEM_TAG, subfields: { g: 'archarch' })]
25
+ end
24
26
 
25
- it 'returns format values of "Archive" for a record with holdings located in "musearch"' do
27
+ it 'returns format values of "Archive"' do
26
28
  expect(formats).to include 'Archive'
27
29
  end
28
30
  end
29
31
 
30
- context 'with a record in "Nursing Archives (nursarch)"' do
31
- let(:record) { marc_record fields: [marc_field(tag: 'hld', subfields: { c: 'nursarch' })] }
32
+ context 'without encoded archive location' do
33
+ let(:record) do
34
+ marc_record fields: [marc_field(tag: '852', subfields: { c: 'notanarchive' }),
35
+ marc_field(tag: PennMARC::Enriched::Pub::ITEM_TAG, subfields: { g: 'notanarchive' })]
36
+ end
32
37
 
33
- it 'returns format values of without "Archive" for a record with a holding in "nursarch"' do
38
+ it 'does not return format values of "Archive"' do
34
39
  expect(formats).not_to include 'Archive'
35
40
  end
36
41
  end
@@ -47,9 +52,6 @@ describe 'PennMARC::Format' do
47
52
  end
48
53
  end
49
54
 
50
- # TODO: confirm this as desired functionality
51
- # Inspired by https://franklin.library.upenn.edu/catalog/FRANKLIN_999444703503681
52
- # which appears to be a thesis on microfilm, but only has microfilm as a format.
53
55
  context 'with a "Thesis" on "Microfilm"' do
54
56
  let(:record) do
55
57
  marc_record leader: ' tm',
@@ -59,8 +61,8 @@ describe 'PennMARC::Format' do
59
61
  ]
60
62
  end
61
63
 
62
- it 'returns a facet value of only "Microformat"' do
63
- expect(formats).to eq %w[Microformat]
64
+ it 'returns all format values that meet the format facet encoding rules' do
65
+ expect(formats).to contain_exactly('Manuscript', 'Microformat', 'Thesis/Dissertation', 'Book')
64
66
  end
65
67
  end
66
68
 
@@ -95,6 +97,84 @@ describe 'PennMARC::Format' do
95
97
  end
96
98
  end
97
99
 
100
+ context 'with Microformats as determined by MARC control fields' do
101
+ context 'with 007 field' do
102
+ let(:record) do
103
+ marc_record fields: [marc_control_field(tag: '007', value: 'h')]
104
+ end
105
+
106
+ it 'returns "Microformat"' do
107
+ expect(formats).to contain_exactly('Microformat')
108
+ end
109
+ end
110
+
111
+ context 'with 008 field and valid value at position 23' do
112
+ let(:record) do
113
+ marc_record fields: [
114
+ marc_control_field(tag: '008', value: ' a')
115
+ ]
116
+ end
117
+
118
+ it 'returns "Microformat"' do
119
+ expect(formats).to contain_exactly('Microformat')
120
+ end
121
+ end
122
+
123
+ context 'with 008 field and valid value at position 29' do
124
+ let(:record) do
125
+ marc_record fields: [
126
+ marc_control_field(tag: '008', value: ' a')
127
+ ]
128
+ end
129
+
130
+ it 'returns "Microformat"' do
131
+ expect(formats).to contain_exactly('Microformat')
132
+ end
133
+ end
134
+ end
135
+
136
+ context 'with Microformats as determined by title medium' do
137
+ let(:record) do
138
+ marc_record(fields: [marc_field(tag: '245', subfields: { h: 'micro' })])
139
+ end
140
+
141
+ it 'returns "Microformat"' do
142
+ expect(formats).to contain_exactly('Microformat')
143
+ end
144
+ end
145
+
146
+ context 'with Microformats as determined by media type' do
147
+ let(:record) do
148
+ marc_record(fields: [marc_field(tag: '337', subfields: { a: 'microform' })])
149
+ end
150
+
151
+ it 'returns "Microformat"' do
152
+ expect(formats).to contain_exactly('Microformat')
153
+ end
154
+ end
155
+
156
+ context 'with "Manuscript"' do
157
+ context 'with valid manuscript format code in leader' do
158
+ let(:record) do
159
+ marc_record(leader: ' t')
160
+ end
161
+
162
+ it 'returns "Manuscript"' do
163
+ expect(formats).to contain_exactly('Manuscript')
164
+ end
165
+ end
166
+
167
+ context 'without valid manuscript format code in leader' do
168
+ let(:record) do
169
+ marc_record(leader: ' a')
170
+ end
171
+
172
+ it 'does not return "Manuscript"' do
173
+ expect(formats).not_to include('Manuscript')
174
+ end
175
+ end
176
+ end
177
+
98
178
  context 'with a "Book"' do
99
179
  let(:record) do
100
180
  marc_record leader: ' aa',
@@ -104,6 +184,33 @@ describe 'PennMARC::Format' do
104
184
  it 'returns a facet value including only "Book"' do
105
185
  expect(formats).to eq ['Book']
106
186
  end
187
+
188
+ context 'with a media type that contains "micro"' do
189
+ let(:record) do
190
+ marc_record leader: ' aa',
191
+ fields: [
192
+ marc_field(tag: '245', subfields: { k: 'blah' }),
193
+ marc_field(tag: '337', subfields: { a: 'microform' })
194
+ ]
195
+ end
196
+
197
+ it 'does not return a facet value including "Book"' do
198
+ expect(formats).not_to include('Book')
199
+ end
200
+ end
201
+
202
+ context 'with a 245 $k value of "kit"' do
203
+ let(:record) do
204
+ marc_record leader: ' tm',
205
+ fields: [
206
+ marc_field(tag: '245', subfields: { k: 'kit' })
207
+ ]
208
+ end
209
+
210
+ it 'does not return a facet value including "Book"' do
211
+ expect(formats).not_to include('Book')
212
+ end
213
+ end
107
214
  end
108
215
 
109
216
  context 'with a "Projected Graphic"' do
@@ -126,7 +233,7 @@ describe 'PennMARC::Format' do
126
233
  let(:subfield_a_value) { 'Book' }
127
234
 
128
235
  it 'returns a facet value including a curated format of "Book"' do
129
- expect(formats).to eq %w[Other Book]
236
+ expect(formats).to eq ['Book']
130
237
  end
131
238
  end
132
239
 
@@ -138,6 +245,28 @@ describe 'PennMARC::Format' do
138
245
  end
139
246
  end
140
247
  end
248
+
249
+ context 'with Other' do
250
+ context 'with another facet applied' do
251
+ let(:record) do
252
+ marc_record(leader: ' t')
253
+ end
254
+
255
+ it 'does not return "Other"' do
256
+ expect(formats).not_to include 'Other'
257
+ end
258
+ end
259
+
260
+ context 'without another facet applied' do
261
+ let(:record) do
262
+ marc_record(leader: ' z')
263
+ end
264
+
265
+ it 'returns "Other"' do
266
+ expect(formats).to contain_exactly 'Other'
267
+ end
268
+ end
269
+ end
141
270
  end
142
271
 
143
272
  describe '.show' do
@@ -235,19 +364,19 @@ describe 'PennMARC::Format' do
235
364
  end
236
365
 
237
366
  describe '.includes_manuscript?' do
238
- context 'with a manuscript location included' do
239
- let(:locations) { ['Van Pelt', 'Kislak Center for Special Collections - Manuscripts Storage'] }
367
+ context 'with a valid manuscript format code' do
368
+ let(:format_code) { 't' }
240
369
 
241
370
  it 'returns true' do
242
- expect(helper.include_manuscripts?(locations)).to be true
371
+ expect(helper.include_manuscripts?(format_code)).to be true
243
372
  end
244
373
  end
245
374
 
246
- context 'without a manuscript location included' do
247
- let(:locations) { ['Van Pelt'] }
375
+ context 'without a valid manuscript format code' do
376
+ let(:format_code) { 'at' }
248
377
 
249
378
  it 'returns false' do
250
- expect(helper.include_manuscripts?(locations)).to be false
379
+ expect(helper.include_manuscripts?(format_code)).to be false
251
380
  end
252
381
  end
253
382
  end
@@ -43,11 +43,7 @@ describe 'PennMARC::Genre' do
43
43
  end
44
44
 
45
45
  describe '.facet' do
46
- let(:values) { helper.facet(record, location_map: location_map) }
47
- let(:location_map) do
48
- { manu: { specific_location: 'Secure Manuscripts Storage' },
49
- vanp: { specific_location: 'Van Pelt' } }
50
- end
46
+ let(:values) { helper.facet(record) }
51
47
 
52
48
  context 'with a non-video, non-manuscript record' do
53
49
  let(:fields) do
@@ -74,10 +70,10 @@ describe 'PennMARC::Genre' do
74
70
  end
75
71
  end
76
72
 
77
- context 'with a manuscript-located record' do
73
+ context 'with a manuscript record' do
74
+ let(:record) { marc_record fields: fields, leader: ' t' }
78
75
  let(:fields) do
79
76
  [marc_control_field(tag: '007', value: 'x'),
80
- marc_field(tag: 'hld', subfields: { c: 'manu' }),
81
77
  marc_field(tag: '655', indicator2: '7', subfields: { a: 'Astronomy', '2': 'zzzz' })]
82
78
  end
83
79
 
@@ -276,7 +276,7 @@ describe 'PennMARC::Note' do
276
276
  marc_field(tag: '880', subfields: { a: 'Alt video format', b: 'Alt broadcast', '3': 'Alt materials.',
277
277
  '6': '346' }),
278
278
  marc_field(tag: '880', subfields: { a: 'Alt file type', b: 'Alt encoding', '3': 'Alt materials.',
279
- '6': 'Alt region' })
279
+ '6': '347-02' })
280
280
 
281
281
  ]
282
282
  end
@@ -292,7 +292,8 @@ text for URI http://www.universal.resource/locator'.squish,
292
292
  'Alt materials Alt system details Alternative display text Alt URI',
293
293
  'Alt materials Alt recording Alt medium Alt playing speed Alt channel Alt characteristic',
294
294
  'Alt materials Alt presentation format Alt projection speed',
295
- 'Alt materials Alt video format Alt broadcast'
295
+ 'Alt materials Alt video format Alt broadcast',
296
+ 'Alt materials Alt file type Alt encoding'
296
297
  )
297
298
  end
298
299
  end
@@ -66,10 +66,25 @@ describe 'PennMARC::Relation' do
66
66
 
67
67
  it 'returns specified subfield values from specified field with blank indicator2' do
68
68
  values = helper.related_work_show record, relator_map: relator_map
69
- expect(values).to contain_exactly 'Translation of: Some Author Aphorisms, Translator',
69
+ expect(values).to contain_exactly 'Translation of: Some Author Aphorisms, Translator.',
70
70
  'Alt. Prefix: Alt. Author Alt. Aphorisms'
71
71
  expect(values).not_to include 'Ignored'
72
72
  end
73
+
74
+ context 'with a translatable relator code in a 711 field and its linked alternate' do
75
+ let(:fields) do
76
+ [marc_field(tag: '711', indicator2: '', subfields: { i: 'Index to (work):', a: 'The Law of Outer Space',
77
+ e: 'Advisory Board', j: 'author', t: 'Proceedings' }),
78
+ marc_field(tag: '880', indicator2: '', subfields: { i: 'Alt. Prefix:', a: 'Alt. Name', j: 'author',
79
+ t: 'Alt. Title', '6': '711' })]
80
+ end
81
+
82
+ it 'appends relator term found in $j' do
83
+ values = helper.related_work_show(record, relator_map: relator_map)
84
+ expect(values).to contain_exactly('Index to: The Law of Outer Space Advisory Board Proceedings, author.',
85
+ 'Alt. Prefix: Alt. Name Alt. Title, author.')
86
+ end
87
+ end
73
88
  end
74
89
 
75
90
  describe '.contains_show' do
@@ -77,14 +92,43 @@ describe 'PennMARC::Relation' do
77
92
  [marc_field(tag: '700', indicator2: '2', subfields: { i: 'Container of (work):', a: 'Some Author', t: 'Works',
78
93
  '4': 'aut' }),
79
94
  marc_field(tag: '700', indicator2: '', subfields: { i: 'Adaptation of (work):', t: 'Ignored' }),
80
- marc_field(tag: '880', indicator2: '2', subfields: { i: 'Alt. Prefix:', a: 'Alt. Name', '6': '700' })]
95
+ marc_field(tag: '880', indicator2: '2', subfields: { i: 'Alt. Prefix:', a: 'Alt. Name', e: 'Alt relator',
96
+ '6': '700' })]
81
97
  end
82
98
 
83
99
  it "returns specified subfield values from specified field with '2' in indicator2" do
84
100
  values = helper.contains_show record, relator_map: relator_map
85
- expect(values).to contain_exactly 'Alt. Prefix: Alt. Name', 'Container of: Some Author Works, Author'
101
+ expect(values).to contain_exactly 'Alt. Prefix: Alt. Name, Alt relator.',
102
+ 'Container of: Some Author Works, Author.'
86
103
  expect(values).not_to include 'Ignored'
87
104
  end
105
+
106
+ context 'with a translatable relator code in a 711 field and its linked alternate' do
107
+ let(:fields) do
108
+ [marc_field(tag: '711', indicator2: '2', subfields: { i: 'Index to (work):', a: 'The Law of Outer Space',
109
+ e: 'Advisory Board', j: 'author', t: 'Proceedings' }),
110
+ marc_field(tag: '880', indicator2: '2', subfields: { i: 'Alt. Prefix:', a: 'Alt. Name', j: 'author',
111
+ t: 'Alt. Title', '6': '711' })]
112
+ end
113
+
114
+ it 'appends relator term found in $j' do
115
+ values = helper.contains_show(record, relator_map: relator_map)
116
+ expect(values).to contain_exactly('Index to: The Law of Outer Space Advisory Board Proceedings, author.',
117
+ 'Alt. Prefix: Alt. Name Alt. Title, author.')
118
+ end
119
+ end
120
+
121
+ context 'with translatable relator codes in a linked alternate' do
122
+ let(:fields) do
123
+ [marc_field(tag: '880', indicator2: '2', subfields: { i: 'Alt. Prefix:', a: 'Alt. Name', '4': 'aut',
124
+ '6': '700' })]
125
+ end
126
+
127
+ it 'appends translatable relator codes' do
128
+ values = helper.contains_show record, relator_map: relator_map
129
+ expect(values).to contain_exactly 'Alt. Prefix: Alt. Name, Author.'
130
+ end
131
+ end
88
132
  end
89
133
 
90
134
  describe '.constituent_unit_show' do
@@ -216,4 +216,122 @@ describe 'PennMARC::Util' do
216
216
  expect(values).not_to include 'Regular Local Heading', 'LoC Heading', 'Another Alt.'
217
217
  end
218
218
  end
219
+
220
+ describe '.field_or_its_linked_alternate?' do
221
+ let(:field) { marc_field(tag: '100', subfields: { a: 'Sylvia Wynter' }) }
222
+ let(:linked_alternate) { marc_field(tag: '880', subfields: { '6': '100' }) }
223
+
224
+ it "returns true when tags include the field's tag" do
225
+ expect(util.field_or_its_linked_alternate?(field, %w[100 200])).to be true
226
+ end
227
+
228
+ it "returns true when tags include linked alternate's $6 value" do
229
+ expect(util.field_or_its_linked_alternate?(linked_alternate, %w[100 200])).to be true
230
+ end
231
+
232
+ it "returns false when tags exclude the field's tag" do
233
+ expect(util.field_or_its_linked_alternate?(field, %w[200 300])).to be false
234
+ end
235
+
236
+ it "returns false when tags exclude the linked alternate's $6 value" do
237
+ expect(util.field_or_its_linked_alternate?(linked_alternate, %w[200 300])).to be false
238
+ end
239
+ end
240
+
241
+ describe '.relator_join_separator' do
242
+ it 'returns a space when string ends with an open date' do
243
+ expect(util.relator_join_separator('Nalo Hopkinson 1960-')).to be ' '
244
+ end
245
+
246
+ it 'returns a comma and a space (", ") when string does not end with an open date' do
247
+ expect(util.relator_join_separator('Audre Lorde 1934-1992')).to be ', '
248
+ end
249
+
250
+ context 'when a word character precedes the open date' do
251
+ it 'returns a comma and a space (", ")' do
252
+ expect(util.relator_join_separator('word120-')).to be ', '
253
+ end
254
+ end
255
+ end
256
+
257
+ describe '.relator_term_subfield' do
258
+ context 'with a field that uses $j for relator term' do
259
+ let(:field) { marc_field(tag: '111', subfields: { a: 'Code4Lib' }) }
260
+
261
+ it 'returns "j"' do
262
+ expect(util.relator_term_subfield(field)).to eq 'j'
263
+ end
264
+ end
265
+
266
+ context 'with any field that does not use $j for relator term' do
267
+ let(:field) { marc_field(tag: '100', subfields: { a: 'J.R.R. Tolkien' }) }
268
+
269
+ it 'defaults to "e"' do
270
+ expect(util.relator_term_subfield(field)).to eq 'e'
271
+ end
272
+ end
273
+ end
274
+
275
+ describe '.append_relator' do
276
+ let(:joined_subfields) { field.subfields.first.value }
277
+ let(:relator_map) { { aut: 'Author', ill: 'Illustrator' } }
278
+ let(:result) { util.append_relator(field: field, joined_subfields: joined_subfields, relator_term_sf: 'e') }
279
+
280
+ context 'when joined subfield values ends with a a comma' do
281
+ let(:field) { marc_field(tag: '100', subfields: { a: 'Capus, Alex,', '4': 'aut' }) }
282
+
283
+ it 'removes the trailing comma before joining the relator' do
284
+ expect(result).to eq 'Capus, Alex, Author.'
285
+ end
286
+ end
287
+
288
+ context 'with relator term and translatable relator code' do
289
+ let(:field) { marc_field(tag: '100', subfields: { a: 'Capus, Alex', e: 'editor', '4': 'aut' }) }
290
+
291
+ it 'only appends translatable relator' do
292
+ expect(result).to eq 'Capus, Alex, Author.'
293
+ end
294
+ end
295
+
296
+ context 'with multiple translatable relator codes' do
297
+ let(:field) { marc_field(tag: '100', subfields: { a: 'Capus, Alex', e: 'editor', '4': %w[aut ill doi] }) }
298
+
299
+ it 'appends all translatable relators with expected punctuation' do
300
+ expect(result).to eq 'Capus, Alex, Author, Illustrator.'
301
+ end
302
+ end
303
+
304
+ context 'with multiple relator terms' do
305
+ let(:field) { marc_field(tag: '100', subfields: { a: 'Capus, Alex', e: %w[author illustrator] }) }
306
+
307
+ it 'appends all translatable relators with expected punctuation' do
308
+ expect(result).to eq 'Capus, Alex, author, illustrator.'
309
+ end
310
+ end
311
+
312
+ context 'without translatable relator code' do
313
+ let(:field) { marc_field(tag: '100', subfields: { a: 'Capus, Alex,', e: %w[author illustrator], '4': 'doi' }) }
314
+
315
+ it 'appends relator term' do
316
+ expect(result).to eq 'Capus, Alex, author, illustrator.'
317
+ end
318
+ end
319
+
320
+ context 'when relator term has trailing period' do
321
+ let(:field) { marc_field(tag: '100', subfields: { a: 'Capus, Alex,', e: 'author.' }) }
322
+
323
+ it 'punctuates the value as expected' do
324
+ expect(result).to eq 'Capus, Alex, author.'
325
+ end
326
+ end
327
+
328
+ context 'when joined subfield values ends with an open date' do
329
+ let(:joined_subfields) { [field.subfields.first.value, field.subfields.second.value].join(' ') }
330
+ let(:field) { marc_field(tag: '100', subfields: { a: 'Capus, Alex,', d: '1808-', '4': %w[aut ill] }) }
331
+
332
+ it 'uses a space when appending the relator' do
333
+ expect(result).to eq 'Capus, Alex, 1808- Author, Illustrator.'
334
+ end
335
+ end
336
+ end
219
337
  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.18
4
+ version: 1.0.20
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-04-18 00:00:00.000000000 Z
13
+ date: 2024-05-22 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport