pennmarc 1.0.3 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitleaks.toml +2 -0
- data/.rubocop_todo.yml +7 -35
- data/lib/pennmarc/helpers/access.rb +52 -0
- data/lib/pennmarc/helpers/date.rb +4 -8
- data/lib/pennmarc/helpers/language.rb +23 -8
- data/lib/pennmarc/mappers.rb +6 -2
- data/lib/pennmarc/mappings/iso639-3-languages.yml +7916 -0
- data/lib/pennmarc/util.rb +8 -0
- data/lib/pennmarc/version.rb +1 -1
- data/spec/lib/pennmarc/helpers/access_spec.rb +58 -0
- data/spec/lib/pennmarc/helpers/creator_spec.rb +10 -5
- data/spec/lib/pennmarc/helpers/date_spec.rb +16 -0
- data/spec/lib/pennmarc/helpers/identifer_spec.rb +0 -1
- data/spec/lib/pennmarc/helpers/language_spec.rb +56 -8
- data/spec/lib/pennmarc/helpers/series_spec.rb +5 -3
- data/spec/lib/pennmarc/marc_util_spec.rb +12 -0
- data/spec/lib/pennmarc/parser_spec.rb +3 -3
- metadata +7 -3
- /data/lib/pennmarc/mappings/{language.yml → iso639-2-languages.yml} +0 -0
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,58 @@
|
|
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) do
|
11
|
+
marc_record fields: [marc_field(tag: 'prt')]
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'returns expected access value' do
|
15
|
+
expect(helper.facet(record)).to contain_exactly(PennMARC::Access::ONLINE)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'with a print record' do
|
20
|
+
let(:record) do
|
21
|
+
marc_record fields: [marc_field(tag: 'hld')]
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'returns expected access value' do
|
25
|
+
expect(helper.facet(record)).to contain_exactly(PennMARC::Access::AT_THE_LIBRARY)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'with a record containing a link to a finding aid (as a handle link)' do
|
30
|
+
let(:record) do
|
31
|
+
marc_record fields: [marc_field(tag: 'hld'),
|
32
|
+
marc_field(tag: '856', subfields: location_and_access_subfields, **indicators)]
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'with an 856 describing a related record, not the record itself' do
|
36
|
+
let(:indicators) { { indicator1: '4', indicator2: '2' } }
|
37
|
+
let(:location_and_access_subfields) do
|
38
|
+
{ z: 'Finding Aid', u: 'http://hdl.library.upenn.edu/1017/d/pacscl/UPENN_RBML_MsColl200' }
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'does not include online access' do
|
42
|
+
expect(helper.facet(record)).not_to include PennMARC::Access::ONLINE
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'with an 865 describing a link to a finding aid' do
|
47
|
+
let(:indicators) { { indicator1: '4', indicator2: '1' } }
|
48
|
+
let(:location_and_access_subfields) do
|
49
|
+
{ z: 'Finding aid', u: 'http://hdl.library.upenn.edu/1017/d/pacscl/UPENN_RBML_MsColl200' }
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'includes online access' do
|
53
|
+
expect(helper.facet(record)).to contain_exactly(PennMARC::Access::ONLINE, PennMARC::Access::AT_THE_LIBRARY)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
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
|
@@ -27,6 +27,22 @@ describe 'PennMARC::Date' do
|
|
27
27
|
end
|
28
28
|
|
29
29
|
describe '.added' do
|
30
|
+
context 'with a robust itm tag' do
|
31
|
+
let(:fields) do
|
32
|
+
[marc_field(tag: 'itm', subfields: { g: 'VanPeltLib', i: 'Tw .156', q: '2023-10-19' })]
|
33
|
+
end
|
34
|
+
|
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')
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'does not output any warning to STDOUT' do
|
40
|
+
expect {
|
41
|
+
helper.added(record)
|
42
|
+
}.not_to output(a_string_including('Error parsing date in date added subfield')).to_stdout
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
30
46
|
context "with date formatted '%Y-%m-%d'" do
|
31
47
|
let(:fields) { [marc_field(tag: 'itm', subfields: { q: '2023-06-28' })] }
|
32
48
|
|
@@ -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
|
|
@@ -4,27 +4,75 @@ describe 'PennMARC::Language' do
|
|
4
4
|
include MarcSpecHelpers
|
5
5
|
|
6
6
|
let(:helper) { PennMARC::Language }
|
7
|
-
let(:
|
8
|
-
{ eng: 'English', und: 'Undetermined' }
|
7
|
+
let(:iso_639_2_mapping) do
|
8
|
+
{ eng: 'English', und: 'Undetermined', fre: 'French', ger: 'German', ulw: 'Ulwa' }
|
9
|
+
end
|
10
|
+
let(:iso_639_3_mapping) do
|
11
|
+
{ eng: 'American', und: 'Undetermined', fre: 'Francais', ger: 'Deutsch', twf: 'Northern Tiwa' }
|
9
12
|
end
|
10
13
|
let(:record) do
|
11
14
|
marc_record fields: [
|
12
15
|
marc_control_field(tag: '008', value: ' eng'),
|
16
|
+
marc_field(tag: '041', subfields: { '2': 'iso639-2', a: 'eng', b: 'fre', d: 'ger' }),
|
13
17
|
marc_field(tag: '546', subfields: { a: 'Great', c: 'Content', '6': 'Not Included' }),
|
14
18
|
marc_field(tag: '546', subfields: { b: 'More!', '8': 'Not Included' }),
|
15
19
|
marc_field(tag: '880', subfields: { c: 'Mas!', '6': '546', '8': 'Not Included' })
|
16
20
|
]
|
17
21
|
end
|
18
22
|
|
19
|
-
describe '.search' do
|
20
|
-
it 'returns the expected display value' do
|
21
|
-
expect(helper.search(record, language_map: mapping)).to eq 'English'
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
23
|
describe '.show' do
|
26
24
|
it 'returns the expected show values' do
|
27
25
|
expect(helper.show(record)).to contain_exactly 'Great Content', 'More!', 'Mas!'
|
28
26
|
end
|
29
27
|
end
|
28
|
+
|
29
|
+
describe '.search' do
|
30
|
+
context 'when using iso 639-2 spec' do
|
31
|
+
it 'returns the expected display values from iso639-2' do
|
32
|
+
expect(helper.values(record,
|
33
|
+
iso_639_2_mapping: iso_639_2_mapping,
|
34
|
+
iso_639_3_mapping: iso_639_3_mapping)).to contain_exactly('English', 'French', 'German')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'when using iso639-3 spec' do
|
39
|
+
let(:record) do
|
40
|
+
marc_record fields: [marc_field(tag: '041', subfields: { '2': 'iso639-3', a: 'eng', b: 'fre', d: 'ger' }),
|
41
|
+
marc_field(tag: '041', subfields: { '2': 'iso639-3', a: 'twf' })]
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'returns the expected display values from iso639-3' do
|
45
|
+
expect(helper.values(record,
|
46
|
+
iso_639_2_mapping: iso_639_2_mapping,
|
47
|
+
iso_639_3_mapping: iso_639_3_mapping)).to contain_exactly('American', 'Francais',
|
48
|
+
'Deutsch', 'Northern Tiwa')
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'when using multiple specs' do
|
53
|
+
let(:record) do
|
54
|
+
marc_record fields: [marc_field(tag: '041', subfields: { '2': 'iso639-3', a: 'eng', b: 'fre', d: 'ger' }),
|
55
|
+
marc_field(tag: '041', subfields: { '2': 'iso639-2', a: 'ulw' })]
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'returns the expected display values from iso639-3' do
|
59
|
+
expect(helper.values(record,
|
60
|
+
iso_639_2_mapping: iso_639_2_mapping,
|
61
|
+
iso_639_3_mapping: iso_639_3_mapping)).to contain_exactly('American', 'Francais',
|
62
|
+
'Deutsch', 'Ulwa')
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context 'with an empty record' do
|
67
|
+
let(:record) do
|
68
|
+
marc_record fields: [marc_field(tag: '041', subfields: { c: 'test' })]
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'returns undetermined when there are no values' do
|
72
|
+
expect(helper.values(record,
|
73
|
+
iso_639_2_mapping: iso_639_2_mapping,
|
74
|
+
iso_639_3_mapping: iso_639_3_mapping)).to contain_exactly('Undetermined')
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
30
78
|
end
|
@@ -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
|
|
@@ -8,12 +8,12 @@ describe PennMARC::Parser do
|
|
8
8
|
let(:record) { record_from 'test.xml' }
|
9
9
|
|
10
10
|
it 'delegates to helper modules properly' do
|
11
|
-
expect(parser.
|
11
|
+
expect(parser.language_values(record)).to contain_exactly 'English'
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'delegates to helper modules properly with extra params' do
|
15
15
|
bogus_map = { eng: 'American' }
|
16
|
-
expect(parser.
|
16
|
+
expect(parser.language_values(record, iso_639_2_mapping: bogus_map)).to contain_exactly 'American'
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'raises an exception if the method call is invalid' do
|
@@ -23,7 +23,7 @@ describe PennMARC::Parser do
|
|
23
23
|
|
24
24
|
describe '#respond_to?' do
|
25
25
|
it 'returns true if a helper has the expected method' do
|
26
|
-
expect(parser).to respond_to :
|
26
|
+
expect(parser).to respond_to :language_values
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'returns false if a helper does not have the expected method' do
|
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.5
|
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
|
@@ -77,6 +77,7 @@ extensions: []
|
|
77
77
|
extra_rdoc_files: []
|
78
78
|
files:
|
79
79
|
- ".gitignore"
|
80
|
+
- ".gitleaks.toml"
|
80
81
|
- ".rspec"
|
81
82
|
- ".rubocop.yml"
|
82
83
|
- ".rubocop_todo.yml"
|
@@ -88,6 +89,7 @@ files:
|
|
88
89
|
- lib/pennmarc/encoding_level.rb
|
89
90
|
- lib/pennmarc/enriched_marc.rb
|
90
91
|
- lib/pennmarc/heading_control.rb
|
92
|
+
- lib/pennmarc/helpers/access.rb
|
91
93
|
- lib/pennmarc/helpers/citation.rb
|
92
94
|
- lib/pennmarc/helpers/creator.rb
|
93
95
|
- lib/pennmarc/helpers/database.rb
|
@@ -107,7 +109,8 @@ files:
|
|
107
109
|
- lib/pennmarc/helpers/subject.rb
|
108
110
|
- lib/pennmarc/helpers/title.rb
|
109
111
|
- lib/pennmarc/mappers.rb
|
110
|
-
- lib/pennmarc/mappings/
|
112
|
+
- lib/pennmarc/mappings/iso639-2-languages.yml
|
113
|
+
- lib/pennmarc/mappings/iso639-3-languages.yml
|
111
114
|
- lib/pennmarc/mappings/locations.yml
|
112
115
|
- lib/pennmarc/mappings/relator.yml
|
113
116
|
- lib/pennmarc/parser.rb
|
@@ -115,6 +118,7 @@ files:
|
|
115
118
|
- lib/pennmarc/version.rb
|
116
119
|
- pennmarc.gemspec
|
117
120
|
- spec/fixtures/marcxml/test.xml
|
121
|
+
- spec/lib/pennmarc/helpers/access_spec.rb
|
118
122
|
- spec/lib/pennmarc/helpers/citation_spec.rb
|
119
123
|
- spec/lib/pennmarc/helpers/creator_spec.rb
|
120
124
|
- spec/lib/pennmarc/helpers/database_spec.rb
|
File without changes
|