pennmarc 1.0.2 → 1.0.3

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: 33527bf43532170690b9b591097fb03f854130b3383debfafe931417d0394f52
4
- data.tar.gz: a18a5be08df6d7b74d2aaa61275cdecdedec6caa4b5e8b2b81c99e91411ce093
3
+ metadata.gz: 28dc70104803899434767b340182cb8eecff8c402cfb5e8547058d560a45a1e5
4
+ data.tar.gz: 1fc0897f12ffb24de8bc0f40b69474d29264c036e33ba4ea97390b60a9f60c43
5
5
  SHA512:
6
- metadata.gz: 627a4da06351037f520bc02b0a9fd61ce6cfdec35c563f2b29e3c1c01b4ad76766f155630cafe680b010783ea4f4c285df2d499fd784b7ee4f3cb4948cd421dd
7
- data.tar.gz: c966233bb00009a14babc5bc92f0399e75640e886f7c32d176fea8983813aca8936d0e8fab98576a797afaf0b60c5f24268c2ae4e2d8cca31900e590db0a9bc6
6
+ metadata.gz: c82d8a22f480a768a8f6cce3cb7bc2ed25f7d5b202e3b492ac572a6f5bfec0d801098e1d74db8eb470573a2afbdd9314a90e18955a576c9ff5dee42aa2fbc5cd
7
+ data.tar.gz: d3c69ce76e13c50b0f2da649ea9499dcb93a734944d298cb783e71e0c4bc59c76fad0ea344353124f024524d11b5f8c92318771d780848506d50940f483c427b
data/README.md CHANGED
@@ -73,7 +73,7 @@ rspec
73
73
 
74
74
  1. Update the version in `pennmarc.gemspec`
75
75
  2. Run `gem build pennmarc.gemspec` with the latest code
76
- 3. Run `gem push pennmarc-{version number here}`(e.g. `gem push pennmarc-1.0.0`) to push to RubyGems. You will need access and MFA setup with RubyGems.
76
+ 3. Run `gem push pennmarc-{version number here}.gem`(e.g. `gem push pennmarc-1.0.0.gem`) to push to RubyGems. You will need access and MFA setup with RubyGems.
77
77
 
78
78
  ## QA
79
79
 
@@ -89,4 +89,4 @@ MARC_FILE=path/to/marc.xml bundle exec rake pennmarc:parse
89
89
  - rake task or some similar command to return a full set of values extracted from a specified marcxml file
90
90
  - Pipeline to run tests and publish to Rubygems
91
91
  - rubocop check
92
- - rdoc/yard coverage checks?
92
+ - rdoc/yard coverage checks?
@@ -41,10 +41,10 @@ module PennMARC
41
41
  results += record.fields('880').map do |f|
42
42
  subfield_to_ignore = if subfield_value?(f, 6, /^300/)
43
43
  %w[3 6 8]
44
- elsif subfield_value?(f, 6, /^(254|255|310|342|352|362)/)
45
- %w[6 8]
46
44
  elsif subfield_value?(f, 6, /^340/)
47
45
  %w[0 2 6 8]
46
+ else
47
+ %w[6 8]
48
48
  end
49
49
  join_subfields(f, &subfield_not_in?(subfield_to_ignore))
50
50
  end
@@ -23,7 +23,7 @@ module PennMARC
23
23
  if field.tag == '020'
24
24
  field.filter_map { |subfield| normalize_isbn(subfield.value) if subfield_in?(%w[a z]).call(subfield) }
25
25
  else
26
- field.filter_map { |subfield| subfield.value if subfield_in?(%w[a l z]).call(subfield) }
26
+ field.filter_map { |subfield| subfield.value if subfield_in?(%w[a l m y z]).call(subfield) }
27
27
  end
28
28
  }.flatten.uniq
29
29
  end
@@ -56,21 +56,42 @@ module PennMARC
56
56
 
57
57
  # Get numeric OCLC ID of first {https://www.oclc.org/bibformats/en/0xx/035.html 035 field}
58
58
  # with an OCLC ID defined in subfield 'a'.
59
- #
60
- # @todo We should evaluate this to return a single value in the future since subfield a is non-repeatable
61
59
  # @param [MARC::Record] record
62
- # @return [Array<String>]
63
- def oclc_id(record)
64
- oclc_id = Array.wrap(record.fields('035')
65
- .find { |field| field.any? { |subfield| subfield_a_is_oclc?(subfield) } })
66
-
67
- oclc_id.flat_map do |field|
60
+ # @return [String, nil]
61
+ def oclc_id_show(record)
62
+ ids = Array.wrap(record.fields('035')
63
+ .find { |field| field.any? { |subfield| subfield_a_is_oclc?(subfield) } })
64
+ ids.flat_map { |field|
68
65
  field.filter_map do |subfield|
69
66
  # skip unless subfield 'a' is an oclc id value
70
67
  next unless subfield_a_is_oclc?(subfield)
71
68
 
72
69
  # search for numeric part of oclc id (e.g. '610094484' in '(OCoLC)ocn610094484')
73
- match = /^\s*\(OCoLC\)[^1-9]*([1-9][0-9]*).*$/.match(subfield.value)
70
+ match = match_oclc_number(subfield)
71
+
72
+ # skip unless search to find numeric part of oclc id has a match
73
+ next unless match
74
+
75
+ match[1]
76
+ end
77
+ }.first
78
+ end
79
+
80
+ # Retrieve valid and invalid numeric OCLC IDs from {https://www.oclc.org/bibformats/en/0xx/035.html 035 field}
81
+ # for search.
82
+ # @param [MARC::Record] record
83
+ # @return [Array<String>]
84
+ def oclc_id_search(record)
85
+ record.fields('035').flat_map do |field|
86
+ field.filter_map do |subfield|
87
+ # skip unless subfield 'a' or 'z'
88
+ next unless subfield.code.in?(%w[a z])
89
+
90
+ # skip unless subfield value matches OCLC ID
91
+ next unless subfield_is_oclc?(subfield)
92
+
93
+ # search for numeric part of oclc id
94
+ match = match_oclc_number(subfield)
74
95
 
75
96
  # skip unless search to find numeric part of oclc id has a match
76
97
  next unless match
@@ -143,7 +164,19 @@ module PennMARC
143
164
  # @param [MARC::Subfield]
144
165
  # @return [TrueClass, FalseClass]
145
166
  def subfield_a_is_oclc?(subfield)
146
- subfield.code == 'a' && (subfield.value =~ /^\(OCoLC\).*/).present?
167
+ subfield.code == 'a' && subfield_is_oclc?(subfield)
168
+ end
169
+
170
+ # @param [MARC::Subfield]
171
+ # @return [TrueClass, FalseClass]
172
+ def subfield_is_oclc?(subfield)
173
+ (subfield.value =~ /^\(OCoLC\).*/).present?
174
+ end
175
+
176
+ # @param [MARC::Subfield]
177
+ # @return [MatchData, nil]
178
+ def match_oclc_number(subfield)
179
+ /^\s*\(OCoLC\)[^1-9]*([1-9][0-9]*).*$/.match(subfield.value)
147
180
  end
148
181
 
149
182
  # Normalize isbn value using {https://github.com/billdueber/library_stdnums library_stdnums gem}.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PennMARC
4
- VERSION = '1.0.2'
4
+ VERSION = '1.0.3'
5
5
  end
@@ -17,13 +17,15 @@ describe 'PennMARC::Identifier' do
17
17
  let(:record) do
18
18
  marc_record fields: [
19
19
  marc_field(tag: '020', subfields: { a: '9781594205071', z: '1555975275' }),
20
- marc_field(tag: '022', subfields: { a: '0008-6533', l: '0300-7162', z: '0799-5946 ' })
20
+ marc_field(tag: '022',
21
+ subfields: { a: '0008-6533', l: '0300-7162', m: 'cancelled', y: 'incorrect', z: '0799-5946' })
21
22
  ]
22
23
  end
23
24
 
24
25
  it 'returns expected search values' do
25
26
  expect(helper.isxn_search(record)).to contain_exactly('9781594205071', '1555975275', '9781555975272',
26
- '1594205078', '0300-7162', '0008-6533', '0799-5946 ')
27
+ '1594205078', '0300-7162', '0008-6533', '0799-5946',
28
+ 'cancelled', 'incorrect')
27
29
  end
28
30
 
29
31
  it 'converts ISBN10 values to ISBN13' do
@@ -62,7 +64,7 @@ describe 'PennMARC::Identifier' do
62
64
  end
63
65
  end
64
66
 
65
- describe '.oclc_id' do
67
+ describe '.oclc_id_show' do
66
68
  let(:record) do
67
69
  marc_record fields: [
68
70
  marc_field(tag: '035', subfields: { a: '(PU)4422776-penndb-Voyager' }),
@@ -72,7 +74,21 @@ describe 'PennMARC::Identifier' do
72
74
  end
73
75
 
74
76
  it 'returns expected show values' do
75
- expect(helper.oclc_id(record)).to contain_exactly('610094484')
77
+ expect(helper.oclc_id_show(record)).to eq '610094484'
78
+ end
79
+ end
80
+
81
+ describe '.oclc_id_search' do
82
+ let(:record) do
83
+ marc_record fields: [
84
+ marc_field(tag: '035', subfields: { a: '(PU)4422776-penndb-Voyager' }),
85
+ marc_field(tag: '035', subfields: { z: '(OCoLC)ocn610094484' }),
86
+ marc_field(tag: '035', subfields: { a: '(OCoLC)ocn1483169584' })
87
+ ]
88
+ end
89
+
90
+ it 'returns expected search values' do
91
+ expect(helper.oclc_id_search(record)).to contain_exactly('610094484', '1483169584')
76
92
  end
77
93
  end
78
94
 
@@ -146,4 +162,4 @@ describe 'PennMARC::Identifier' do
146
162
  '10.1038/sdata.2016.18', '10.18574/9781479842865')
147
163
  end
148
164
  end
149
- end
165
+ end
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pennmarc
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Kanning
8
8
  - Amrey Mathurin
9
9
  - Patrick Perkins
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2023-10-06 00:00:00.000000000 Z
13
+ date: 2023-10-12 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -140,7 +140,7 @@ licenses:
140
140
  - MIT
141
141
  metadata:
142
142
  rubygems_mfa_required: 'true'
143
- post_install_message:
143
+ post_install_message:
144
144
  rdoc_options: []
145
145
  require_paths:
146
146
  - lib
@@ -156,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
156
  version: '0'
157
157
  requirements: []
158
158
  rubygems_version: 3.4.10
159
- signing_key:
159
+ signing_key:
160
160
  specification_version: 4
161
161
  summary: Penn Libraries Catalog MARC parsing wisdom for cross-project usage
162
162
  test_files: []