pennmarc 1.3.0 → 1.3.2

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: 6f422c1bb424ebc17da2ba97c65d4e248b6704be27a6f0a5fbc6d871e17c995e
4
- data.tar.gz: cdf55d046c6ea17d28393c1d9b1b3bf8803d6435a53db34d3e824494d09f7b4c
3
+ metadata.gz: b69f7173f51a48c0748bf1d537392c6bda0919312009c85bd70e603cf4cb0240
4
+ data.tar.gz: fa0e2d2c724e26734890fcc1fe4e20899a6141d0e0f0cdebe9e242b03070be35
5
5
  SHA512:
6
- metadata.gz: c166a340a11acbabb7fed4b5ae05f20490e41d00783e03032516bcd5ef6bda4db764160379a5d617bbcee3d8adbc067a6288e68d3e2de9fdbb94b4468f1971a1
7
- data.tar.gz: 50dbc268e26a309062d811b336566ea61c5062725af13c14482ab31a8f91bb2ed2fa5b1f1d2b4c5e408b6104da6a871482778775a359d90396263c0548a193cc
6
+ metadata.gz: 4ed0b2699d095d4f07483e38fd99d8bcc52d2fd69f8c6b94dfba410a8d6f42329dda379e7eb8809ec43687d8552cc38471f85859ff0d73c0888026845caed1e6
7
+ data.tar.gz: 62d4f90ff259a2188fc0cc5eee803cd18e9f1a83d15874de77ef956e6dd836ae6a822a433770c0e56e2f583c15f696919be30f7298c080b4404d27e3f247d245
@@ -5,7 +5,8 @@ module PennMARC
5
5
  class Access < Helper
6
6
  ONLINE = 'Online'
7
7
  AT_THE_LIBRARY = 'At the library'
8
- RESOURCE_LINK_BASE_URL = 'hdl.library.upenn.edu'
8
+ HANDLE_BASE_URL = 'hdl.library.upenn.edu'
9
+ COLENDA_BASE_URL = 'colenda.library.upenn.edu'
9
10
 
10
11
  class << self
11
12
  # Based on enhanced metadata fields added by Alma publishing process or API, determine if the record has
@@ -46,7 +47,7 @@ module PennMARC
46
47
  # Check if a record contains an 856 entry with a Penn Handle server link meeting these criteria:
47
48
  # 1. Indicator 1 is 4 (HTTP resource)
48
49
  # 2. Indicator 2 is NOT 2 (indicating the linkage is to a "related" thing)
49
- # 3. The URL specified in subfield u (URI) is a Penn Handle link
50
+ # 3. The URL specified in subfield u (URI) is a Penn Handle link or Penn Colenda link
50
51
  # 4. The subfield z does NOT include the string 'Finding aid'
51
52
  # See: https://www.loc.gov/marc/bibliographic/bd856.html
52
53
  # @note Some electronic records do not have Portfolios in Alma, so we rely upon the Resource Link in the 856 to
@@ -54,15 +55,19 @@ module PennMARC
54
55
  # @param record [MARC::Record]
55
56
  # @return [Boolean]
56
57
  def resource_link?(record)
57
- record.fields('856').filter_map do |field|
58
- next if field.indicator2 == '2' || field.indicator1 != '4'
58
+ record.fields('856').any? { |field| valid_resource_field?(field) }
59
+ end
60
+
61
+ # Check if a field contains valid resource
62
+ # @param field [MARC::Field]
63
+ # @return [Boolean]
64
+ def valid_resource_field?(field)
65
+ return false if field.indicator2 == '2' || field.indicator1 != '4'
66
+ return false if subfield_values(field, 'z')&.include?('Finding aid')
59
67
 
60
- subz = subfield_values(field, 'z')
61
- subfield_values(field, 'u').filter_map do |value|
62
- return true if subz.exclude?('Finding aid') && value.include?(RESOURCE_LINK_BASE_URL)
63
- end
68
+ subfield_values(field, 'u').any? do |value|
69
+ [HANDLE_BASE_URL, COLENDA_BASE_URL].any? { |url| value.include?(url) }
64
70
  end
65
- false
66
71
  end
67
72
  end
68
73
  end
@@ -85,6 +85,36 @@ module PennMARC
85
85
  creators.to_h { |h| [h[:show], h[:facet]] }
86
86
  end
87
87
 
88
+ # Show more credited authors - both 100 field and 700 entries where the relator (codes e or 4) is author/aut
89
+ # @param record [MARC::Record]
90
+ # @return [Array<String>] array of author/creator values for display
91
+ def extended_show(record, relator_map: Mappers.relator)
92
+ fields = record.fields(%w[100 700])
93
+ fields.filter_map { |field|
94
+ # for 700 entries, only include ones with relator code ('4') = aut, or code 'e' = 'author'
95
+ next if field.tag == '700' && !(field['4']&.downcase == 'aut' || field['e']&.downcase&.start_with?('author'))
96
+
97
+ parse_show_value(field, relator_map: relator_map)
98
+ }.uniq
99
+ end
100
+
101
+ # Hash with extended creators show values as the fields and the corresponding facet as the values.
102
+ # Only include 100, and 700 with relator (codes e or 4) of author/aut
103
+ # @param record [MARC::Record]
104
+ # @param relator_map [Hash]
105
+ # @return [Hash]
106
+ def extended_show_facet_map(record, relator_map: Mappers.relator)
107
+ creators = record.fields(%w[100 700]).filter_map do |field|
108
+ # for 700 entries, only include ones with relator code ('4') = aut, or code 'e' = 'author'
109
+ next if field.tag == '700' && !(field['4']&.downcase == 'aut' || field['e']&.downcase&.start_with?('author'))
110
+
111
+ show = parse_show_value(field, relator_map: relator_map)
112
+ facet = parse_facet_value(field, FACET_SOURCE_MAP[field.tag.to_i].chars)
113
+ { show: show, facet: facet }
114
+ end
115
+ creators.to_h { |h| [h[:show], h[:facet]] }
116
+ end
117
+
88
118
  # Returns the list of authors with name (subfield $a) only
89
119
  # @param record [MARC::Record]
90
120
  # @param main_tags_only [Boolean] only use TAGS; otherwise use both TAGS and CONTRIBUTOR_TAGS
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PennMARC
4
- VERSION = '1.3.0'
4
+ VERSION = '1.3.2'
5
5
  end
@@ -44,7 +44,7 @@ describe 'PennMARC::Access' do
44
44
  end
45
45
  end
46
46
 
47
- context 'with a record containing a link to a finding aid (as a handle link)' do
47
+ context 'with a record containing a link to an online resource' do
48
48
  let(:record) do
49
49
  marc_record fields: [marc_field(tag: PennMARC::Enriched::Pub::PHYS_INVENTORY_TAG),
50
50
  marc_field(tag: '856', subfields: location_and_access_subfields, **indicators)]
@@ -72,7 +72,7 @@ describe 'PennMARC::Access' do
72
72
  end
73
73
  end
74
74
 
75
- context 'with an 856 describing a resource link' do
75
+ context 'with an 856 describing a handle resource link' do
76
76
  let(:indicators) { { indicator1: '4', indicator2: '1' } }
77
77
  let(:location_and_access_subfields) do
78
78
  { z: 'Connect to resource', u: 'http://hdl.library.upenn.edu/1234' }
@@ -82,6 +82,28 @@ describe 'PennMARC::Access' do
82
82
  expect(helper.facet(record)).to contain_exactly(PennMARC::Access::ONLINE, PennMARC::Access::AT_THE_LIBRARY)
83
83
  end
84
84
  end
85
+
86
+ context 'with an 856 describing a colenda resource link' do
87
+ let(:indicators) { { indicator1: '4', indicator2: '1' } }
88
+ let(:location_and_access_subfields) do
89
+ { z: 'Connect to resource', u: 'http://colenda.library.upenn.edu/1234' }
90
+ end
91
+
92
+ it 'includes online access' do
93
+ expect(helper.facet(record)).to contain_exactly(PennMARC::Access::ONLINE, PennMARC::Access::AT_THE_LIBRARY)
94
+ end
95
+ end
96
+
97
+ context 'with an 856 describing some other resource link' do
98
+ let(:indicators) { { indicator1: '4', indicator2: '1' } }
99
+ let(:location_and_access_subfields) do
100
+ { z: 'Connect to resource', u: 'http://vanpelt.upenn.edu/something' }
101
+ end
102
+
103
+ it 'does not includes online access' do
104
+ expect(helper.facet(record)).not_to include PennMARC::Access::ONLINE
105
+ end
106
+ end
85
107
  end
86
108
  end
87
109
  end
@@ -93,6 +93,55 @@ describe 'PennMARC::Creator' do
93
93
  end
94
94
  end
95
95
 
96
+ describe '.extended_show' do
97
+ let(:record) { marc_record fields: fields }
98
+
99
+ context 'with a single author record' do
100
+ let(:fields) do
101
+ [marc_field(tag: '100', subfields: { a: 'Surname, Name', '0': 'http://cool.uri/12345', d: '1900-2000',
102
+ e: 'author.', '4': 'http://cool.uri/vocabulary/relators/aut' }),
103
+ marc_field(tag: '880', subfields: { a: 'Surname, Alternative', '6': '100' })]
104
+ end
105
+
106
+ it 'returns single author values with no URIs anywhere (the same as show)' do
107
+ values = helper.extended_show(record)
108
+ expect(values).to contain_exactly 'Surname, Name 1900-2000, author.'
109
+ expect(values.join.downcase).not_to include 'http'
110
+ end
111
+ end
112
+
113
+ context 'with author records in 100 and 700' do
114
+ let(:fields) do
115
+ [marc_field(tag: '100', subfields: { a: 'Surname, Name', '0': 'http://cool.uri/12345', d: '1900-2000',
116
+ e: 'author.', '4': 'http://cool.uri/vocabulary/relators/aut' }),
117
+ marc_field(tag: '700', subfields: { a: 'Surname, Alternative', '6': '100', '4': 'aut' }),
118
+ marc_field(tag: '700', subfields: { a: 'Surname, Third', e: 'author.', '6': '100' }),
119
+ marc_field(tag: '700', subfields: { a: 'Surname, Ignore', e: 'editor.', '6': '100' }),
120
+ marc_field(tag: '700', subfields: { a: 'Surname, Not Included', '6': '100', '4': 'edt' })]
121
+ end
122
+
123
+ it 'returns three authors' do
124
+ values = helper.extended_show(record)
125
+ expect(values).to contain_exactly 'Surname, Name 1900-2000, author.',
126
+ 'Surname, Alternative, Author.', 'Surname, Third, author.'
127
+ expect(values.join.downcase).not_to include 'http'
128
+ end
129
+ end
130
+
131
+ context 'with no 100 or 700 fields' do
132
+ let(:fields) do
133
+ [marc_field(tag: '110', subfields: { a: 'Group of People', b: 'Annual Meeting', '4': 'aut' }),
134
+ marc_field(tag: '880', subfields: { '6': '110', a: 'Alt. Group Name', b: 'Alt. Annual Meeting' })]
135
+ end
136
+
137
+ it 'returns empty' do
138
+ values = helper.extended_show(record, relator_map: mapping)
139
+ expect(values).to be_empty
140
+ expect(values.join.downcase).not_to include 'http'
141
+ end
142
+ end
143
+ end
144
+
96
145
  describe '.authors_list' do
97
146
  let(:record) { marc_record fields: fields }
98
147
 
@@ -198,6 +247,26 @@ describe 'PennMARC::Creator' do
198
247
  end
199
248
  end
200
249
 
250
+ describe '.extended_show_facet_map' do
251
+ let(:record) do
252
+ marc_record fields: [
253
+ marc_field(tag: '100', subfields: { a: 'Surname, Name', '0': 'http://cool.uri/12345', d: '1900-2000',
254
+ e: 'author.', '4': 'http://cool.uri/vocabulary/relators/aut' }),
255
+ marc_field(tag: '700', subfields: { a: 'Group of People', b: 'Annual Meeting', '4': 'aut' }),
256
+ marc_field(tag: '700', subfields: { a: 'Second Group of People', b: 'Meeting', '4': 'aut' }),
257
+ marc_field(tag: '700', subfields: { a: 'Ignore (not author)', '4': 'edt' }),
258
+ marc_field(tag: '880', subfields: { a: 'Ignore', '6': '100' })
259
+ ]
260
+ end
261
+
262
+ it 'returns expected hash' do
263
+ values = helper.extended_show_facet_map(record, relator_map: mapping)
264
+ expect(values).to eq({ 'Surname, Name 1900-2000, author.' => 'Surname, Name 1900-2000',
265
+ 'Group of People Annual Meeting, Author.' => 'Group of People Annual Meeting',
266
+ 'Second Group of People Meeting, Author.' => 'Second Group of People Meeting' })
267
+ end
268
+ end
269
+
201
270
  describe '.show_aux' do
202
271
  let(:record) { marc_record fields: fields }
203
272
 
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.3.0
4
+ version: 1.3.2
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: 2025-08-15 00:00:00.000000000 Z
15
+ date: 2025-08-22 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: activesupport