pennmarc 1.0.21 → 1.0.23

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ec3fde9cb69168e9d4f3221df750bc9b6345409a2e413e0b7117f66f7e1be843
4
- data.tar.gz: 32cb166f43c18235282e10927c9589e9b62b4889c247adf4628a8459a5c4e47c
3
+ metadata.gz: 7c906223a9bcdb4ba4792ac50462b8c57e41e71fa1e83cd8e63018d360ebfe0a
4
+ data.tar.gz: 5d1a420e07734370c95ab1f83d3c519a1d75a7faaa807f1d3ee436808779c586
5
5
  SHA512:
6
- metadata.gz: 3e114ad5839e035a3297f45548a4dccad0bd3b752b01126612307c0cb08d30cf2d2da7a752f6049a48014e9145c7fdb882294a936b998f5d6c644154609ec21d
7
- data.tar.gz: 3d2874d2d62231efb4d887ae14fc69ccdc7bd3ca3d4fa929a56c6a7b39b121f10cfc34cb1222e80fdbcac38395b9279d3c05b130c166fe011f93ff7b4a0fea74
6
+ metadata.gz: 32e47c254c1a2bb78e861003c864bdbc22833439cff22ebe00148df081c74fed85f60e2f743b5ea65065e5db576e3a304710b1a68b2cdc1e08a1a5f7808e5fc3
7
+ data.tar.gz: 6051840a95afdcb41640abf2c42ce699deddc93970c5d117cb445474d4f5998996ee05651ec1e59da3e45886e00f6c058b881b1bf9103de92deb5cf6d868ce80
@@ -8,14 +8,14 @@ module PennMARC
8
8
  # Publication date is a four-digit year found in position 7-10 and may contain 'u' characters to represent
9
9
  # partially known dates. We replace any occurrences of 'u' with '0' before converting to DateTime object.
10
10
  # @param [MARC::Record] record
11
- # @return [DateTime, nil] The publication date, or nil if date found in record is invalid
11
+ # @return [Time, nil] The publication date, or nil if date found in record is invalid
12
12
  def publication(record)
13
13
  record.fields('008').filter_map { |field|
14
14
  four_digit_year = sanitize_partially_known_date(field.value[7, 4], '0')
15
15
 
16
16
  next if four_digit_year.blank?
17
17
 
18
- DateTime.new(four_digit_year.to_i)
18
+ Time.new(four_digit_year.to_i)
19
19
  }.first
20
20
  end
21
21
 
@@ -23,7 +23,7 @@ module PennMARC
23
23
  # {PennMARC::Enriched} maps enriched marc fields and subfields created during Alma publishing. The enriched
24
24
  # metadata provided by the Alma API does not include the date created value, so we can't work with that here.
25
25
  # @param [MARC::Record] record
26
- # @return [DateTime, nil] The date added, or nil if date found in record is invalid
26
+ # @return [Time, nil] The date added, or nil if date found in record is invalid
27
27
  def added(record)
28
28
  record.fields(Enriched::Pub::ITEM_TAG).flat_map { |field|
29
29
  subfield_values(field, Enriched::Pub::ITEM_DATE_CREATED).filter_map do |date_added|
@@ -34,9 +34,10 @@ module PennMARC
34
34
 
35
35
  format = date_added.size == 10 ? '%Y-%m-%d' : '%Y-%m-%d %H:%M:%S'
36
36
 
37
- DateTime.strptime(date_added, format)
37
+ Time.strptime(date_added, format)
38
38
  rescue StandardError => e
39
- puts "Error parsing date in date added subfield: #{date_added} - #{e}"
39
+ puts 'Error parsing date in date added subfield. ' \
40
+ "mmsid: #{Identifier.mmsid(record)}, value: #{date_added}, error: #{e}"
40
41
  nil
41
42
  end
42
43
  }.max
@@ -46,7 +47,7 @@ module PennMARC
46
47
  # Date last updated is a sixteen character String recorded in
47
48
  # {https://www.iso.org/iso-8601-date-and-time-format.html ISO 8601} format.
48
49
  # @param [MARC::Record] record
49
- # @return [DateTime, nil] The date last updated, or nil if date found in record is invalid
50
+ # @return [Time, nil] The date last updated, or nil if date found in record is invalid
50
51
  def last_updated(record)
51
52
  record.fields('005').filter_map { |field|
52
53
  begin
@@ -56,9 +57,10 @@ module PennMARC
56
57
 
57
58
  next if date_time_string.start_with?('0000')
58
59
 
59
- DateTime.iso8601(date_time_string).to_datetime
60
- rescue ArgumentError => e
61
- puts "Error parsing last updated date: #{date_time_string} - #{e}"
60
+ Time.strptime(date_time_string, '%Y%m%d%H%M%S.%N')
61
+ rescue StandardError => e
62
+ puts 'Error parsing last updated date. ' \
63
+ "mmsid: #{Identifier.mmsid(record)}, value: #{date_time_string}, error: #{e}"
62
64
  nil
63
65
  end
64
66
  }.first
@@ -47,7 +47,7 @@ module PennMARC
47
47
 
48
48
  locations = record.fields(tag).flat_map { |field|
49
49
  field.filter_map { |subfield|
50
- # skip unless subfield code does not match enriched marc tag subfield code
50
+ # skip unless subfield matches enriched marc tag subfield code
51
51
  next unless subfield.code == location_code_sf
52
52
 
53
53
  location_code = subfield.value
@@ -57,11 +57,7 @@ module PennMARC
57
57
  override = specific_location_override(display_value: display_value, location_code: location_code,
58
58
  field: field, call_num_sf: call_num_sf)
59
59
 
60
- if override.present?
61
- override
62
- else
63
- location_map[location_code.to_sym][display_value.to_sym]
64
- end
60
+ override || location_map[location_code.to_sym][display_value.to_sym]
65
61
  }.flatten.compact_blank
66
62
  }.uniq
67
63
  if record.tags.intersect?([Enriched::Pub::ELEC_INVENTORY_TAG, Enriched::Api::ELEC_INVENTORY_TAG])
@@ -124,25 +120,23 @@ module PennMARC
124
120
 
125
121
  # Retrieves a specific location override based on location code and call number. Specific location overrides are
126
122
  # located in `location_overrides.yml`.
127
- # @param [String] display_value
123
+ # @param [String | Symbol] display_value
128
124
  # @param [String] location_code
129
125
  # @param [MARC::Field] field
130
126
  # @param [String] call_num_sf
131
127
  # @return [String, Nil]
132
128
  def specific_location_override(display_value:, location_code:, field:, call_num_sf:)
133
- return unless display_value == :specific_location
129
+ return unless display_value.to_sym == :specific_location
134
130
 
135
131
  locations_overrides = Mappers.location_overrides
136
132
 
137
133
  call_numbers = subfield_values(field, call_num_sf)
138
134
 
139
- override = locations_overrides.select do |_key, value|
135
+ override = locations_overrides.find do |_key, value|
140
136
  value[:location_code] == location_code && call_numbers.any? { |num| num.match?(value[:call_num_pattern]) }
141
137
  end
142
138
 
143
- return if override.blank?
144
-
145
- override[override.keys.first][:specific_location]
139
+ override&.last&.dig(:specific_location)
146
140
  end
147
141
  end
148
142
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PennMARC
4
- VERSION = '1.0.21'
4
+ VERSION = '1.0.23'
5
5
  end
@@ -10,7 +10,7 @@ describe 'PennMARC::Date' do
10
10
  let(:fields) { [marc_control_field(tag: '008', value: '130827s2010 nyu o 000 1 eng d')] }
11
11
 
12
12
  it 'returns publication date' do
13
- expect(helper.publication(record)).to eq(DateTime.new(2010))
13
+ expect(helper.publication(record)).to eq(Time.new(2010))
14
14
  end
15
15
 
16
16
  it 'returns a year value' do
@@ -33,7 +33,7 @@ describe 'PennMARC::Date' do
33
33
  end
34
34
 
35
35
  it 'returns only the expected date_added value' do
36
- expect(helper.added(record)).to eq DateTime.strptime('2023-10-19', '%Y-%m-%d')
36
+ expect(helper.added(record)).to eq Time.strptime('2023-10-19', '%Y-%m-%d')
37
37
  end
38
38
 
39
39
  it 'does not output any warning to STDOUT' do
@@ -47,7 +47,7 @@ describe 'PennMARC::Date' do
47
47
  let(:fields) { [marc_field(tag: 'itm', subfields: { q: '2023-06-28' })] }
48
48
 
49
49
  it 'returns expected value' do
50
- expect(helper.added(record)).to eq(DateTime.strptime('2023-06-28', '%Y-%m-%d'))
50
+ expect(helper.added(record)).to eq(Time.strptime('2023-06-28', '%Y-%m-%d'))
51
51
  end
52
52
 
53
53
  it 'returns a year value' do
@@ -59,7 +59,7 @@ describe 'PennMARC::Date' do
59
59
  let(:fields) { [marc_field(tag: 'itm', subfields: { q: '2023-06-29 11:04:30:10' })] }
60
60
 
61
61
  it 'returns expected value' do
62
- expect(helper.added(record)).to eq(DateTime.strptime('2023-06-29 11:04:30:10', '%Y-%m-%d %H:%M:%S'))
62
+ expect(helper.added(record)).to eq(Time.strptime('2023-06-29 11:04:30:10', '%Y-%m-%d %H:%M:%S'))
63
63
  end
64
64
 
65
65
  it 'returns a year value' do
@@ -74,12 +74,15 @@ describe 'PennMARC::Date' do
74
74
  end
75
75
 
76
76
  it 'returns most recent date' do
77
- expect(helper.added(record)).to eq(DateTime.strptime('2023-06-29', '%Y-%m-%d'))
77
+ expect(helper.added(record)).to eq(Time.strptime('2023-06-29', '%Y-%m-%d'))
78
78
  end
79
79
  end
80
80
 
81
81
  context 'with invalid date' do
82
- let(:fields) { [marc_field(tag: 'itm', subfields: { q: 'invalid date' })] }
82
+ let(:fields) do
83
+ [marc_control_field(tag: '001', value: 'mmsid'),
84
+ marc_field(tag: 'itm', subfields: { q: 'invalid date' })]
85
+ end
83
86
 
84
87
  it 'returns nil' do
85
88
  expect(helper.added(record)).to be_nil
@@ -88,7 +91,8 @@ describe 'PennMARC::Date' do
88
91
  it 'outputs error message' do
89
92
  expect {
90
93
  helper.added(record)
91
- }.to output("Error parsing date in date added subfield: invalid date - invalid date\n").to_stdout
94
+ }.to output('Error parsing date in date added subfield. mmsid: mmsid, value: invalid date, ' \
95
+ "error: invalid date or strptime format - `invalid date' `%Y-%m-%d %H:%M:%S'\n").to_stdout
92
96
  end
93
97
  end
94
98
  end
@@ -97,7 +101,7 @@ describe 'PennMARC::Date' do
97
101
  let(:fields) { [marc_field(tag: '005', subfields: { q: '20230213163851.1' })] }
98
102
 
99
103
  it 'returns date last updated' do
100
- expect(helper.last_updated(record)).to eq(DateTime.iso8601('20230213163851.1').to_datetime)
104
+ expect(helper.last_updated(record)).to eq(Time.strptime('20230213163851.1', '%Y%m%d%H%M%S.%N'))
101
105
  end
102
106
 
103
107
  it 'returns year value' do
@@ -105,7 +109,10 @@ describe 'PennMARC::Date' do
105
109
  end
106
110
 
107
111
  context 'with invalid date' do
108
- let(:fields) { [marc_field(tag: '005', subfields: { q: 'invalid date' })] }
112
+ let(:fields) do
113
+ [marc_control_field(tag: '001', value: 'mmsid'),
114
+ marc_field(tag: '005', subfields: { q: 'invalid date' })]
115
+ end
109
116
 
110
117
  it 'returns nil' do
111
118
  expect(helper.last_updated(record)).to be_nil
@@ -114,7 +121,8 @@ describe 'PennMARC::Date' do
114
121
  it 'outputs error message' do
115
122
  expect {
116
123
  helper.last_updated(record)
117
- }.to output("Error parsing last updated date: invalid date - invalid date\n").to_stdout
124
+ }.to output('Error parsing last updated date. mmsid: mmsid, value: invalid date, ' \
125
+ "error: invalid date or strptime format - `invalid date' `%Y%m%d%H%M%S.%N'\n").to_stdout
118
126
  end
119
127
  end
120
128
  end
@@ -110,21 +110,26 @@ describe 'PennMARC::Location' do
110
110
  )
111
111
  end
112
112
  end
113
- end
114
113
 
115
- context 'with a specific location override' do
116
- let(:record) do
117
- marc_record(fields: [marc_field(tag: enriched_marc::Pub::ITEM_TAG,
118
- subfields: { enriched_marc::Pub::ITEM_CURRENT_LOCATION => 'vanp',
119
- enriched_marc::Pub::ITEM_CALL_NUMBER => 'ML3534 .D85 1984' }),
120
- marc_field(tag: enriched_marc::Pub::ITEM_TAG,
121
- subfields: { enriched_marc::Pub::ITEM_CURRENT_LOCATION => 'stor',
122
- enriched_marc::Pub::ITEM_CALL_NUMBER => 'L3534 .D85 1984' })])
123
- end
114
+ context 'with a specific location override' do
115
+ let(:record) do
116
+ marc_record(fields: [marc_field(tag: enriched_marc::Pub::ITEM_TAG,
117
+ subfields: { enriched_marc::Pub::ITEM_CURRENT_LOCATION => 'vanp',
118
+ enriched_marc::Pub::ITEM_CALL_NUMBER => 'ML3534 .D85 1984' }),
119
+ marc_field(tag: enriched_marc::Pub::ITEM_TAG,
120
+ subfields: { enriched_marc::Pub::ITEM_CURRENT_LOCATION => 'stor',
121
+ enriched_marc::Pub::ITEM_CALL_NUMBER => 'L3534 .D85 1984' })])
122
+ end
124
123
 
125
- it 'returns expected values' do
126
- expect(helper.location(record: record, display_value: :specific_location, location_map: mapping))
127
- .to(contain_exactly(PennMARC::Mappers.location_overrides[:albrecht][:specific_location], 'LIBRA'))
124
+ it 'returns expected values' do
125
+ expect(helper.location(record: record, display_value: :specific_location, location_map: mapping))
126
+ .to(contain_exactly(PennMARC::Mappers.location_overrides[:albrecht][:specific_location], 'LIBRA'))
127
+ end
128
+
129
+ it 'returns expected values when receiving a string for display_value' do
130
+ expect(helper.location(record: record, display_value: 'specific_location', location_map: mapping))
131
+ .to(contain_exactly(PennMARC::Mappers.location_overrides[:albrecht][:specific_location], 'LIBRA'))
132
+ end
128
133
  end
129
134
  end
130
135
  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.21
4
+ version: 1.0.23
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-05-22 00:00:00.000000000 Z
13
+ date: 2024-06-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport