pennmarc 1.0.4 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +7 -35
- data/lib/pennmarc/helpers/access.rb +68 -0
- data/lib/pennmarc/util.rb +8 -0
- data/lib/pennmarc/version.rb +1 -1
- data/spec/lib/pennmarc/helpers/access_spec.rb +78 -0
- data/spec/lib/pennmarc/helpers/creator_spec.rb +10 -5
- data/spec/lib/pennmarc/helpers/date_spec.rb +1 -1
- data/spec/lib/pennmarc/helpers/identifer_spec.rb +0 -1
- data/spec/lib/pennmarc/helpers/series_spec.rb +5 -3
- data/spec/lib/pennmarc/marc_util_spec.rb +12 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb8a665310aaf17d406fcfbfe562894a71f17d35b2d63173ca587a9c0e343b54
|
4
|
+
data.tar.gz: 671549b45eb522db5f4350aa0743bcd16585398c6c07f71e2d2a772367a0f33c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a1374b40186e61a56e33924a6f76561877af209e3b8486b185599766e5cc7bc1b45362cf4f3f9e18fc5cf2cb4328b46f8b0f83b0e2c374a1f31164bce3b8483
|
7
|
+
data.tar.gz: 7a098756899b310a694dbcc1409516de62ff9897b624ac4783b793de145ac61c497bc183409343269e5e33b7b21a07728fa74148fe6af2ad8aaef8149acd71c5
|
data/.rubocop_todo.yml
CHANGED
@@ -1,36 +1,12 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config --auto-gen-only-exclude --exclude-limit 10000`
|
3
|
-
# on 2023-08
|
3
|
+
# on 2023-11-08 20:19:45 UTC using RuboCop version 1.51.0.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
7
7
|
# versions of RuboCop, may require this file to be generated again.
|
8
8
|
|
9
|
-
# Offense count:
|
10
|
-
# This cop supports safe autocorrection (--autocorrect).
|
11
|
-
# Configuration parameters: EnforcedStyle, IndentationWidth.
|
12
|
-
# SupportedStyles: with_first_argument, with_fixed_indentation
|
13
|
-
Layout/ArgumentAlignment:
|
14
|
-
Exclude:
|
15
|
-
- 'spec/lib/pennmarc/helpers/series_spec.rb'
|
16
|
-
|
17
|
-
# Offense count: 1
|
18
|
-
# This cop supports safe autocorrection (--autocorrect).
|
19
|
-
# Configuration parameters: EnforcedStyle.
|
20
|
-
# SupportedStyles: empty_lines, no_empty_lines
|
21
|
-
Layout/EmptyLinesAroundBlockBody:
|
22
|
-
Exclude:
|
23
|
-
- 'spec/lib/pennmarc/helpers/identifer_spec.rb'
|
24
|
-
|
25
|
-
# Offense count: 1
|
26
|
-
# This cop supports safe autocorrection (--autocorrect).
|
27
|
-
# Configuration parameters: EnforcedStyle.
|
28
|
-
# SupportedStyles: final_newline, final_blank_line
|
29
|
-
Layout/TrailingEmptyLines:
|
30
|
-
Exclude:
|
31
|
-
- 'spec/lib/pennmarc/helpers/identifer_spec.rb'
|
32
|
-
|
33
|
-
# Offense count: 22
|
9
|
+
# Offense count: 23
|
34
10
|
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes, Max.
|
35
11
|
Metrics/AbcSize:
|
36
12
|
Exclude:
|
@@ -38,6 +14,7 @@ Metrics/AbcSize:
|
|
38
14
|
- 'lib/pennmarc/helpers/edition.rb'
|
39
15
|
- 'lib/pennmarc/helpers/format.rb'
|
40
16
|
- 'lib/pennmarc/helpers/genre.rb'
|
17
|
+
- 'lib/pennmarc/helpers/language.rb'
|
41
18
|
- 'lib/pennmarc/helpers/location.rb'
|
42
19
|
- 'lib/pennmarc/helpers/note.rb'
|
43
20
|
- 'lib/pennmarc/helpers/production.rb'
|
@@ -66,6 +43,7 @@ Metrics/CyclomaticComplexity:
|
|
66
43
|
- 'lib/pennmarc/helpers/edition.rb'
|
67
44
|
- 'lib/pennmarc/helpers/format.rb'
|
68
45
|
- 'lib/pennmarc/helpers/genre.rb'
|
46
|
+
- 'lib/pennmarc/helpers/language.rb'
|
69
47
|
- 'lib/pennmarc/helpers/note.rb'
|
70
48
|
- 'lib/pennmarc/helpers/production.rb'
|
71
49
|
- 'lib/pennmarc/helpers/relation.rb'
|
@@ -104,6 +82,7 @@ Metrics/PerceivedComplexity:
|
|
104
82
|
- 'lib/pennmarc/helpers/edition.rb'
|
105
83
|
- 'lib/pennmarc/helpers/format.rb'
|
106
84
|
- 'lib/pennmarc/helpers/genre.rb'
|
85
|
+
- 'lib/pennmarc/helpers/language.rb'
|
107
86
|
- 'lib/pennmarc/helpers/note.rb'
|
108
87
|
- 'lib/pennmarc/helpers/production.rb'
|
109
88
|
- 'lib/pennmarc/helpers/series.rb'
|
@@ -152,16 +131,9 @@ RSpec/FilePath:
|
|
152
131
|
Exclude:
|
153
132
|
- 'spec/lib/pennmarc/parser_spec.rb'
|
154
133
|
|
155
|
-
# Offense count:
|
134
|
+
# Offense count: 6
|
156
135
|
# Configuration parameters: Max, AllowedGroups.
|
157
136
|
RSpec/NestedGroups:
|
158
137
|
Exclude:
|
138
|
+
- 'spec/lib/pennmarc/helpers/access_spec.rb'
|
159
139
|
- 'spec/lib/pennmarc/helpers/format_spec.rb'
|
160
|
-
|
161
|
-
# Offense count: 2
|
162
|
-
# This cop supports safe autocorrection (--autocorrect).
|
163
|
-
# Configuration parameters: Max, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
|
164
|
-
# URISchemes: http, https
|
165
|
-
Layout/LineLength:
|
166
|
-
Exclude:
|
167
|
-
- 'spec/lib/pennmarc/helpers/creator_spec.rb'
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PennMARC
|
4
|
+
# Methods for extracting how a record can be accessed
|
5
|
+
class Access < Helper
|
6
|
+
ONLINE = 'Online'
|
7
|
+
AT_THE_LIBRARY = 'At the library'
|
8
|
+
ELEC_AVAILABILITY_TAG = 'AVE'
|
9
|
+
PHYS_AVAILABILITY_TAG = 'AVA'
|
10
|
+
|
11
|
+
class << self
|
12
|
+
# Based on enhanced metadata fields added by Alma publishing process or API, determine if the record has
|
13
|
+
# electronic access or has physical holdings, and is therefore "Online" or "At the library". If a record is "At
|
14
|
+
# the library", but has a link to a finding aid in the 856 field (matching certain criteria), also add 'Online' as
|
15
|
+
# an access method.
|
16
|
+
# @todo What if none of these criteria match? Should we include "At the library" by default? Records with no value
|
17
|
+
# in this field would be lost if the user selects a facet value.
|
18
|
+
# @param [MARC::Record] record
|
19
|
+
# @return [Array]
|
20
|
+
def facet(record)
|
21
|
+
acc = record.filter_map do |field|
|
22
|
+
next AT_THE_LIBRARY if physical_holding_tag?(field)
|
23
|
+
next ONLINE if electronic_holding_tag?(field)
|
24
|
+
end
|
25
|
+
|
26
|
+
return acc if acc.size == 2 # return early if all values are already present
|
27
|
+
|
28
|
+
acc << ONLINE if acc.exclude?(ONLINE) && finding_aid_linkage?(record) # only check if ONLINE isn't already there
|
29
|
+
acc
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
# Does the record have added electronic holding info?
|
35
|
+
# @param [MARC::Field] field
|
36
|
+
# @return [Boolean]
|
37
|
+
def electronic_holding_tag?(field)
|
38
|
+
field.tag.in? [EnrichedMarc::TAG_ELECTRONIC_INVENTORY, ELEC_AVAILABILITY_TAG]
|
39
|
+
end
|
40
|
+
|
41
|
+
# Does the record have added physical holding info?
|
42
|
+
# @param [MARC::Field] field
|
43
|
+
# @return [Boolean]
|
44
|
+
def physical_holding_tag?(field)
|
45
|
+
field.tag.in? [EnrichedMarc::TAG_HOLDING, PHYS_AVAILABILITY_TAG]
|
46
|
+
end
|
47
|
+
|
48
|
+
# Check if a record contains an 856 entry for an online finding aid, meeting these criteria:
|
49
|
+
# 1. Indicator 1 is 4 (HTTP resource)
|
50
|
+
# 2. Indicator 2 is NOT 2 (indicating the linkage is to a "related" thing)
|
51
|
+
# 3. The URL specified in subfield u (URI) is a Penn Handle link
|
52
|
+
# See: https://www.loc.gov/marc/bibliographic/bd856.html
|
53
|
+
# @param [MARC::Record] record
|
54
|
+
# @return [Boolean]
|
55
|
+
def finding_aid_linkage?(record)
|
56
|
+
record.fields('856').filter_map do |field|
|
57
|
+
next if field.indicator2 == '2' || field.indicator1 != '4'
|
58
|
+
|
59
|
+
subz = subfield_values(field, 'z')
|
60
|
+
subfield_values(field, 'u').filter_map do |value|
|
61
|
+
return true if subz.include?('Finding aid') && value.include?('hdl.library.upenn.edu')
|
62
|
+
end
|
63
|
+
end
|
64
|
+
false
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/lib/pennmarc/util.rb
CHANGED
@@ -5,6 +5,14 @@ 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
|
+
# Check if a given record has a field present by tag (e.g., '041')
|
9
|
+
# @param [MARC::Record] record
|
10
|
+
# @param [String] marc_field
|
11
|
+
# @return [Boolean]
|
12
|
+
def field_defined?(record, marc_field)
|
13
|
+
record.select { |field| field.tag == marc_field }.any?
|
14
|
+
end
|
15
|
+
|
8
16
|
# Join subfields from a field selected based on a provided proc
|
9
17
|
# @param [MARC::DataField] field
|
10
18
|
# @param [Proc] selector
|
data/lib/pennmarc/version.rb
CHANGED
@@ -0,0 +1,78 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe 'PennMARC::Access' do
|
4
|
+
include MarcSpecHelpers
|
5
|
+
|
6
|
+
let(:helper) { PennMARC::Access }
|
7
|
+
|
8
|
+
describe '.facet' do
|
9
|
+
context 'with an electronic record' do
|
10
|
+
let(:record) { marc_record fields: [marc_field(tag: tag)] }
|
11
|
+
|
12
|
+
context 'with enrichment via the Alma publishing process' do
|
13
|
+
let(:tag) { PennMARC::EnrichedMarc::TAG_ELECTRONIC_INVENTORY }
|
14
|
+
|
15
|
+
it 'returns expected access value' do
|
16
|
+
expect(helper.facet(record)).to contain_exactly(PennMARC::Access::ONLINE)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'with enrichment with availability info via the Alma API' do
|
21
|
+
let(:tag) { PennMARC::Access::ELEC_AVAILABILITY_TAG }
|
22
|
+
|
23
|
+
it 'returns expected access value' do
|
24
|
+
expect(helper.facet(record)).to contain_exactly(PennMARC::Access::ONLINE)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'with a print record' do
|
30
|
+
let(:record) { marc_record fields: [marc_field(tag: tag)] }
|
31
|
+
|
32
|
+
context 'with enrichment via the Alma publishing process' do
|
33
|
+
let(:tag) { PennMARC::EnrichedMarc::TAG_HOLDING }
|
34
|
+
|
35
|
+
it 'returns expected access value' do
|
36
|
+
expect(helper.facet(record)).to contain_exactly(PennMARC::Access::AT_THE_LIBRARY)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'with enrichment with availability info via the Alma API' do
|
41
|
+
let(:tag) { PennMARC::Access::PHYS_AVAILABILITY_TAG }
|
42
|
+
|
43
|
+
it 'returns expected access value' do
|
44
|
+
expect(helper.facet(record)).to contain_exactly(PennMARC::Access::AT_THE_LIBRARY)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'with a record containing a link to a finding aid (as a handle link)' do
|
50
|
+
let(:record) do
|
51
|
+
marc_record fields: [marc_field(tag: PennMARC::EnrichedMarc::TAG_HOLDING),
|
52
|
+
marc_field(tag: '856', subfields: location_and_access_subfields, **indicators)]
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'with an 856 describing a related record, not the record itself' do
|
56
|
+
let(:indicators) { { indicator1: '4', indicator2: '2' } }
|
57
|
+
let(:location_and_access_subfields) do
|
58
|
+
{ z: 'Finding Aid', u: 'http://hdl.library.upenn.edu/1017/d/pacscl/UPENN_RBML_MsColl200' }
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'does not include online access' do
|
62
|
+
expect(helper.facet(record)).not_to include PennMARC::Access::ONLINE
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context 'with an 865 describing a link to a finding aid' do
|
67
|
+
let(:indicators) { { indicator1: '4', indicator2: '1' } }
|
68
|
+
let(:location_and_access_subfields) do
|
69
|
+
{ z: 'Finding aid', u: 'http://hdl.library.upenn.edu/1017/d/pacscl/UPENN_RBML_MsColl200' }
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'includes online access' do
|
73
|
+
expect(helper.facet(record)).to contain_exactly(PennMARC::Access::ONLINE, PennMARC::Access::AT_THE_LIBRARY)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -17,9 +17,11 @@ describe 'PennMARC::Creator' do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'contains the expected search field values for a single author work' do
|
20
|
-
expect(helper.search(record, relator_map: mapping)).to eq [
|
21
|
-
|
22
|
-
|
20
|
+
expect(helper.search(record, relator_map: mapping)).to eq [
|
21
|
+
'Name Surname http://cool.uri/12345 author 1900-2000.',
|
22
|
+
'Surname, Name http://cool.uri/12345 author 1900-2000.',
|
23
|
+
'Alternative Surname'
|
24
|
+
]
|
23
25
|
end
|
24
26
|
end
|
25
27
|
|
@@ -58,7 +60,9 @@ describe 'PennMARC::Creator' do
|
|
58
60
|
end
|
59
61
|
|
60
62
|
it 'returns values for the corporate author, including mapped relator code from ǂ4' do
|
61
|
-
expect(helper.values(record, relator_map: mapping)).to contain_exactly
|
63
|
+
expect(helper.values(record, relator_map: mapping)).to contain_exactly(
|
64
|
+
'Annual Report Leader author, Author.'
|
65
|
+
)
|
62
66
|
end
|
63
67
|
end
|
64
68
|
end
|
@@ -146,7 +150,8 @@ describe 'PennMARC::Creator' do
|
|
146
150
|
end
|
147
151
|
|
148
152
|
it 'includes corporate author and creator values from allowed subfields' do
|
149
|
-
expect(values).to contain_exactly 'Conference on Things Earth', 'Series of Things Earth',
|
153
|
+
expect(values).to contain_exactly 'Conference on Things Earth', 'Series of Things Earth',
|
154
|
+
'Thing Institute'
|
150
155
|
end
|
151
156
|
end
|
152
157
|
end
|
@@ -39,7 +39,7 @@ describe 'PennMARC::Date' do
|
|
39
39
|
it 'does not output any warning to STDOUT' do
|
40
40
|
expect {
|
41
41
|
helper.added(record)
|
42
|
-
}.
|
42
|
+
}.not_to output(a_string_including('Error parsing date in date added subfield')).to_stdout
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
@@ -113,7 +113,6 @@ describe 'PennMARC::Identifier' do
|
|
113
113
|
it 'does not return DOI values' do
|
114
114
|
expect(helper.publisher_number_show(record)).not_to include('10.18574/9781479842865')
|
115
115
|
expect(helper.publisher_number_show(record)).not_to include('doi')
|
116
|
-
|
117
116
|
end
|
118
117
|
end
|
119
118
|
|
@@ -19,9 +19,11 @@ describe 'PennMARC::Series' do
|
|
19
19
|
|
20
20
|
describe '.show' do
|
21
21
|
it 'returns the series' do
|
22
|
-
expect(helper.show(record, relator_map: mapping)).to contain_exactly(
|
23
|
-
|
24
|
-
|
22
|
+
expect(helper.show(record, relator_map: mapping)).to contain_exactly(
|
23
|
+
'Bean Bagatolvski 1997- bk. 1',
|
24
|
+
'Teachings of the feathered pillow',
|
25
|
+
'Учения пернатой подушки', 'Evil Giant Megacorp'
|
26
|
+
)
|
25
27
|
end
|
26
28
|
end
|
27
29
|
|
@@ -7,6 +7,18 @@ describe 'PennMARC::Util' do
|
|
7
7
|
Class.new { extend PennMARC::Util }
|
8
8
|
end
|
9
9
|
|
10
|
+
describe '.field_defined?' do
|
11
|
+
let(:record) { marc_record fields: [marc_field(tag: '100')] }
|
12
|
+
|
13
|
+
it 'returns true if the field is present in the record' do
|
14
|
+
expect(util.field_defined?(record, '100')).to be true
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'returns false if the field is not present in the record' do
|
18
|
+
expect(util.field_defined?(record, '101')).to be false
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
10
22
|
describe '.join_subfields' do
|
11
23
|
let(:field) { marc_field subfields: { a: 'bad', '1': 'join', '3': '', '9': 'subfields' } }
|
12
24
|
|
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.6
|
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: 2023-
|
13
|
+
date: 2023-11-09 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
@@ -89,6 +89,7 @@ files:
|
|
89
89
|
- lib/pennmarc/encoding_level.rb
|
90
90
|
- lib/pennmarc/enriched_marc.rb
|
91
91
|
- lib/pennmarc/heading_control.rb
|
92
|
+
- lib/pennmarc/helpers/access.rb
|
92
93
|
- lib/pennmarc/helpers/citation.rb
|
93
94
|
- lib/pennmarc/helpers/creator.rb
|
94
95
|
- lib/pennmarc/helpers/database.rb
|
@@ -117,6 +118,7 @@ files:
|
|
117
118
|
- lib/pennmarc/version.rb
|
118
119
|
- pennmarc.gemspec
|
119
120
|
- spec/fixtures/marcxml/test.xml
|
121
|
+
- spec/lib/pennmarc/helpers/access_spec.rb
|
120
122
|
- spec/lib/pennmarc/helpers/citation_spec.rb
|
121
123
|
- spec/lib/pennmarc/helpers/creator_spec.rb
|
122
124
|
- spec/lib/pennmarc/helpers/database_spec.rb
|