pennmarc 1.0.22 → 1.0.23
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 +4 -4
- data/lib/pennmarc/helpers/date.rb +11 -9
- data/lib/pennmarc/version.rb +1 -1
- data/spec/lib/pennmarc/helpers/date_spec.rb +18 -10
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c906223a9bcdb4ba4792ac50462b8c57e41e71fa1e83cd8e63018d360ebfe0a
|
4
|
+
data.tar.gz: 5d1a420e07734370c95ab1f83d3c519a1d75a7faaa807f1d3ee436808779c586
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 [
|
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
|
-
|
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 [
|
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
|
-
|
37
|
+
Time.strptime(date_added, format)
|
38
38
|
rescue StandardError => e
|
39
|
-
puts
|
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 [
|
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
|
-
|
60
|
-
rescue
|
61
|
-
puts
|
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
|
data/lib/pennmarc/version.rb
CHANGED
@@ -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(
|
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
|
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(
|
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(
|
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(
|
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)
|
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(
|
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(
|
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)
|
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(
|
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
|
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.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-
|
13
|
+
date: 2024-06-04 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|