pennmarc 1.4.12 → 1.5.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ed8428b56d9ed1e81912885aef968ba0f104f647491afd2498e4e3893748b9c4
4
- data.tar.gz: fead988cff9b7cb56201510a7eba63152dd16f8e691ece753d6b306158afc53e
3
+ metadata.gz: dcc109123084f574bef4157fed192262a5d14ddc4f143acd96994b43512ac7ff
4
+ data.tar.gz: 8a71fceb7682a55e157455a2a3c90c13e8b9b915ad480e735df54b4170a6aeb2
5
5
  SHA512:
6
- metadata.gz: 21e44d07cd4bde553e717f84a944dd297055f94518a27a14f9d9fb3d64c3f1f9172746af0ba0d9e1549fb69198a7ef5f5c23b5323189bba500d04cc5ace40a32
7
- data.tar.gz: caaf7925c9d91833c92ba25524dc70f4bad6f4b31c7640ff35823f20477d5d9c7b7449770bd8ffdcd66fde1a39460ddbad58666d71eeeb22ca3b225f5da72d9a
6
+ metadata.gz: 1cd2813eec3614536eddffaf0f69caa104da3f38fec9e066fc489c24b148a902ed93dc3271595fc9e2d28cf90d076bb82384ec783ab3f530105223219698865b
7
+ data.tar.gz: 1a1801e36c0b03ec8b37de9a76518dd3c79aa7333590ecdc9ec6b4a86064dacdff180295d666a1c98fe7476062d174a3ad4f421ea85ee59aefa24d0aa7a4930d
data/README.md CHANGED
@@ -20,14 +20,14 @@ This gem provides configuration as well as a method for overriding and removing
20
20
  you can remove or replace the configured terms like so:
21
21
 
22
22
  ```ruby
23
- improved_values = PennMARC::HeadingControl.term_override(values)
23
+ improved_value = PennMARC::HeadingControl.term_override(value)
24
24
  ```
25
25
 
26
- This will remove any elements of the `values` array that include any terms defined in [`headings_remove.yml`](lib/pennmarc/mappings/headings_remove.yml) and
27
- replace any terms defined in the [`headings_override.yml`](lib/pennmarc/mappings/headings_override.yml) file.
26
+ This will remove the term (return nil) if `value` is included in `headings_remove.yml`](lib/pennmarc/mappings/headings_remove.yml) and replace it if it matches any of the terms defined
27
+ in the [`headings_override.yml`](lib/pennmarc/mappings/headings_override.yml) file.
28
28
 
29
29
  By default, terms are replaced for `Subject#*show` and `Subject#facet` methods. You can bypass the default overriding on
30
- on these methods by passing `override: false`.
30
+ on these methods by passing `override: false`. Decomposed LCSH headings are also subject to overriding.
31
31
 
32
32
  ## Development
33
33
 
@@ -18,7 +18,7 @@ module PennMARC
18
18
  editions = record.fields('250').map do |field|
19
19
  join_subfields(field, &subfield_not_in?(%w[6 7 8]))
20
20
  end
21
- editions += linked_alternate_not_6_or_8(record, '250') if with_alternate
21
+ editions += linked_alternate_not_6_7_8(record, '250') if with_alternate
22
22
 
23
23
  editions.uniq
24
24
  end
@@ -89,10 +89,8 @@ module PennMARC
89
89
  term_hash = build_subject_hash(field, override)
90
90
  next if term_hash.blank? || term_hash[:count]&.zero?
91
91
 
92
- heading = format_term type: :display, term: term_hash
93
- main_term = "#{trim_trailing(:period, term_hash[:subfield_a])}." if term_hash[:lcsh] && term_hash[:subfield_a]
94
-
95
- [heading, main_term].compact_blank
92
+ [format_term(type: :display, term: term_hash),
93
+ main_term_for(field: field, term: term_hash, override: override)].compact_blank
96
94
  }.flatten.uniq
97
95
  end
98
96
 
@@ -193,6 +191,20 @@ module PennMARC
193
191
  term[:override] ? HeadingControl.term_override(value) : value
194
192
  end
195
193
 
194
+ # Process and return the "main term" (sf a) from a field, overriding if necessary
195
+ # @param field [MARC::DataField]
196
+ # @param term [Hash]
197
+ # @param override [Boolean]
198
+ # @return [String, nil]
199
+ def main_term_for(field:, term:, override:)
200
+ return unless term[:lcsh] && term[:subfield_a]
201
+
202
+ subfield_a_term = "#{trim_trailing(:period, term[:subfield_a])}."
203
+ return HeadingControl.term_override(subfield_a_term) if override && HeadingControl.overrideable_field?(field)
204
+
205
+ subfield_a_term
206
+ end
207
+
196
208
  # Is a field intended for display in a general subject field? To be included, the field tag is in either
197
209
  # {DISPLAY_TAGS} or {LOCAL_TAGS}, and has an indicator 2 value that is in {VALID_SOURCE_INDICATORS}. If
198
210
  # indicator 2 is '7' - indicating "source specified", the specified source must be in our approved source code
data/lib/pennmarc/util.rb CHANGED
@@ -194,27 +194,26 @@ module PennMARC
194
194
  end
195
195
  end
196
196
 
197
- # Common case of wanting to extract all the subfields besides 6 or 8,
198
- # from 880 datafield that has a particular subfield 6 value. We exclude 6 because
199
- # that value is the linkage ID itself and 8 because... IDK
197
+ # Common case of wanting to extract all the subfields besides 6, 7 or 8,
198
+ # from 880 datafield that has a particular subfield 6 value.
200
199
  # @param record [MARC::Record]
201
200
  # @param subfield6_value [String, Array] either a string to look for in sub6 or an array of them
202
201
  # @return [Array] array of linked alternates without 8 or 6 values
203
- def linked_alternate_not_6_or_8(record, subfield6_value)
204
- excluded_subfields = %w[6 8]
202
+ def linked_alternate_not_6_7_8(record, subfield6_value)
203
+ excluded_subfields = %w[6 7 8]
205
204
  linked_alternate(record, subfield6_value) do |sf|
206
205
  excluded_subfields.exclude?(sf.code)
207
206
  end
208
207
  end
209
208
 
210
- # Returns the non-6,8 subfields from a datafield and its 880 link.
209
+ # Returns the non-6,7,8 subfields from a datafield and its 880 link.
211
210
  # @param record [MARC::Record]
212
211
  # @param tag [String]
213
212
  # @return [Array<String>] values
214
213
  def datafield_and_linked_alternate(record, tag)
215
214
  record.fields(tag).filter_map { |field|
216
- join_subfields(field, &subfield_not_in?(%w[6 8]))
217
- } + linked_alternate_not_6_or_8(record, tag)
215
+ join_subfields(field, &subfield_not_in?(%w[6 7 8]))
216
+ } + linked_alternate_not_6_7_8(record, tag)
218
217
  end
219
218
 
220
219
  # Get the substring of a string up to a given target character
@@ -283,7 +282,7 @@ module PennMARC
283
282
  next unless field.any? { |sf| sf.code == 'a' && sf.value =~ /^(#{prefix}|%#{prefix})/ }
284
283
 
285
284
  elements = field.select(&subfield_in?(%w[a])).map { |sf| sf.value.gsub(/^%?#{prefix}/, '') }
286
- elements << join_subfields(field, &subfield_not_in?(%w[a 6 8 e w 5]))
285
+ elements << join_subfields(field, &subfield_not_in?(%w[a 6 7 8 e w 5]))
287
286
  join_and_squish elements
288
287
  }.uniq
289
288
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PennMARC
4
- VERSION = '1.4.12'
4
+ VERSION = '1.5.0'
5
5
  end
@@ -359,19 +359,24 @@ describe 'PennMARC::Subject' do
359
359
 
360
360
  context 'with headings that contain terms for removal and replacement' do
361
361
  let(:fields) do
362
- [marc_field(tag: '650', subfields: { a: 'History.' }),
363
- marc_field(tag: '650', subfields: { a: PennMARC::Mappers.headings_to_remove.first }),
364
- marc_field(tag: '650', subfields: { a: PennMARC::Mappers.heading_overrides.first[0] })]
362
+ [marc_field(tag: '650', subfields: { a: PennMARC::Mappers.headings_to_remove.first }),
363
+ marc_field(tag: '650', indicator2: '0',
364
+ subfields: { a: PennMARC::Mappers.heading_overrides.first[0],
365
+ z: 'United States', x: 'History' })]
365
366
  end
366
367
 
367
368
  it 'removes and replaces terms as expected' do
368
- expect(values).to contain_exactly 'History.', "#{PennMARC::Mappers.heading_overrides.first[1]}."
369
+ expect(values).to contain_exactly(
370
+ "#{PennMARC::Mappers.heading_overrides.first[1]}--United States--History.",
371
+ "#{PennMARC::Mappers.heading_overrides.first[1]}."
372
+ )
369
373
  end
370
374
 
371
375
  it 'does not remove or replace terms if override param is false' do
372
376
  expect(helper.show(record, override: false)).to contain_exactly(
373
- 'History.', "#{PennMARC::Mappers.headings_to_remove.first}.",
374
- "#{PennMARC::Mappers.heading_overrides.first[0]}."
377
+ "#{PennMARC::Mappers.headings_to_remove.first}.",
378
+ "#{PennMARC::Mappers.heading_overrides.first[0]}.",
379
+ "#{PennMARC::Mappers.heading_overrides.first[0]}--United States--History."
375
380
  )
376
381
  end
377
382
  end
@@ -142,11 +142,12 @@ describe 'PennMARC::Util' do
142
142
  describe '.linked_alternate_not_6_or_8' do
143
143
  let(:record) do
144
144
  marc_record fields: [marc_field(tag: '510', subfields: { a: 'Perkins', b: 'Test' }),
145
- marc_field(tag: '880', subfields: { '6': '510', '8': 'Ignore', a: 'Snikrep', b: 'Tset' })]
145
+ marc_field(tag: '880', subfields: { '6': '510', '7': 'blah', '8': 'Ignore', a: 'Snikrep',
146
+ b: 'Tset' })]
146
147
  end
147
148
 
148
- it 'returns the linked alternate without 6 or 8' do
149
- expect(util.linked_alternate_not_6_or_8(record, '510')).to contain_exactly('Snikrep Tset')
149
+ it 'returns the linked alternate without 6, 7 or 8' do
150
+ expect(util.linked_alternate_not_6_7_8(record, '510')).to contain_exactly('Snikrep Tset')
150
151
  end
151
152
  end
152
153
 
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.4.12
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Kanning
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2026-11-11 00:00:00.000000000 Z
15
+ date: 2026-11-13 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: activesupport