pennmarc 1.0.12 → 1.0.15.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/.gitlab-ci.yml +7 -12
  3. data/.rubocop_todo.yml +2 -2
  4. data/lib/pennmarc/enriched.rb +93 -0
  5. data/lib/pennmarc/helpers/access.rb +2 -2
  6. data/lib/pennmarc/helpers/citation.rb +4 -4
  7. data/lib/pennmarc/helpers/classification.rb +8 -8
  8. data/lib/pennmarc/helpers/creator.rb +70 -73
  9. data/lib/pennmarc/helpers/database.rb +6 -6
  10. data/lib/pennmarc/helpers/date.rb +3 -3
  11. data/lib/pennmarc/helpers/edition.rb +4 -2
  12. data/lib/pennmarc/helpers/format.rb +15 -14
  13. data/lib/pennmarc/helpers/helper.rb +1 -1
  14. data/lib/pennmarc/helpers/identifier.rb +16 -14
  15. data/lib/pennmarc/helpers/inventory.rb +92 -0
  16. data/lib/pennmarc/helpers/inventory_entry/base.rb +23 -0
  17. data/lib/pennmarc/helpers/inventory_entry/electronic.rb +20 -0
  18. data/lib/pennmarc/helpers/inventory_entry/physical.rb +38 -0
  19. data/lib/pennmarc/helpers/language.rb +3 -2
  20. data/lib/pennmarc/helpers/location.rb +19 -14
  21. data/lib/pennmarc/helpers/note.rb +10 -8
  22. data/lib/pennmarc/helpers/production.rb +9 -9
  23. data/lib/pennmarc/helpers/relation.rb +12 -9
  24. data/lib/pennmarc/helpers/series.rb +10 -8
  25. data/lib/pennmarc/helpers/subject.rb +12 -12
  26. data/lib/pennmarc/helpers/title.rb +20 -16
  27. data/lib/pennmarc/mappings/locations.yml +4 -0
  28. data/lib/pennmarc/util.rb +19 -4
  29. data/lib/pennmarc/version.rb +1 -1
  30. data/spec/lib/pennmarc/helpers/access_spec.rb +5 -5
  31. data/spec/lib/pennmarc/helpers/classification_spec.rb +6 -6
  32. data/spec/lib/pennmarc/helpers/creator_spec.rb +41 -7
  33. data/spec/lib/pennmarc/helpers/format_spec.rb +4 -4
  34. data/spec/lib/pennmarc/helpers/inventory_spec.rb +129 -0
  35. data/spec/lib/pennmarc/helpers/location_spec.rb +40 -9
  36. data/spec/lib/pennmarc/helpers/subject_spec.rb +37 -13
  37. metadata +10 -5
  38. data/lib/pennmarc/enriched_marc.rb +0 -49
@@ -32,9 +32,9 @@ module PennMARC
32
32
  # a search (non-display) field?
33
33
  # @param [Hash] relator_map
34
34
  # @param [MARC::Record] record
35
- # @return [Array] array of all subject values for search
35
+ # @return [Array<String>] array of all subject values for search
36
36
  def search(record, relator_map: Mappers.relator)
37
- subject_fields(record, type: :search).filter_map do |field|
37
+ subject_fields(record, type: :search).filter_map { |field|
38
38
  subj_parts = field.filter_map do |subfield|
39
39
  # TODO: use term hash here? pro/chr would be rejected...
40
40
  # TODO: should we care about punctuation in a search field? relator mapping?
@@ -55,21 +55,21 @@ module PennMARC
55
55
  next if subj_parts.empty?
56
56
 
57
57
  join_and_squish subj_parts
58
- end
58
+ }.uniq
59
59
  end
60
60
 
61
61
  # All Subjects for faceting
62
62
  #
63
63
  # @note this is ported mostly form MG's new-style Subject parsing
64
64
  # @param [MARC::Record] record
65
- # @return [Array] array of all subject values for faceting
65
+ # @return [Array<String>] array of all subject values for faceting
66
66
  def facet(record)
67
- subject_fields(record, type: :facet).filter_map do |field|
67
+ subject_fields(record, type: :facet).filter_map { |field|
68
68
  term_hash = build_subject_hash(field)
69
69
  next if term_hash.blank? || term_hash[:count]&.zero?
70
70
 
71
71
  format_term type: :facet, term: term_hash
72
- end
72
+ }.uniq
73
73
  end
74
74
 
75
75
  # All Subjects for display. This includes all {DISPLAY_TAGS} and {LOCAL_TAGS}. For tags that specify a source,
@@ -173,9 +173,9 @@ module PennMARC
173
173
 
174
174
  case type.to_sym
175
175
  when :facet
176
- "#{term[:parts].join('--')} #{term[:lasts].join(' ')}".strip
176
+ term[:parts].join('--').strip
177
177
  when :display
178
- "#{term[:parts].join('--')} #{term[:lasts].join(' ')} #{term[:append].join(' ')}".strip
178
+ "#{term[:parts].join('--')} #{term[:append].join(' ')}".strip
179
179
  end
180
180
  end
181
181
 
@@ -227,9 +227,9 @@ module PennMARC
227
227
  # @todo do i need all this?
228
228
  # @todo do i need to handle punctuation? see append_new_part
229
229
  # @param [MARC::DataField] field
230
- # @return [Hash{Symbol->Integer | Array}]
230
+ # @return [Hash{Symbol => Integer, Array}, Nil]
231
231
  def build_subject_hash(field)
232
- term_info = { count: 0, parts: [], append: [], lasts: [], uri: nil,
232
+ term_info = { count: 0, parts: [], append: [], uri: nil,
233
233
  local: field.indicator2 == '4' || field.tag.starts_with?('69'), # local subject heading
234
234
  vernacular: field.tag == '880' }
235
235
  field.each do |subfield|
@@ -251,8 +251,8 @@ module PennMARC
251
251
  # 'e' is relator term; not sure what 'w' is. These are used to append for record-view display only
252
252
  term_info[:append] << subfield.value.strip # TODO: map relator code?
253
253
  when 'b', 'c', 'd', 'p', 'q', 't'
254
- # these are appended to the last component if possible (i.e., when joined, should have no delimiter)
255
- term_info[:lasts] << subfield.value.strip
254
+ # these are appended to the last component (part) if possible (i.e., when joined, should have no delimiter)
255
+ term_info[:parts].last << ", #{subfield.value.strip}"
256
256
  term_info[:count] += 1
257
257
  else
258
258
  # the usual case; add a new component to `parts`
@@ -35,11 +35,11 @@ module PennMARC
35
35
  # @param [MARC::Record] record
36
36
  # @return [Array<String>] array of title values for search
37
37
  def search(record)
38
- record.fields(%w[245 880]).filter_map do |field|
38
+ record.fields(%w[245 880]).filter_map { |field|
39
39
  next if field.tag == '880' && subfield_value_not_in?(field, '6', %w[245])
40
40
 
41
41
  join_subfields(field, &subfield_not_in?(%w[c 6 8 h]))
42
- end
42
+ }.uniq
43
43
  end
44
44
 
45
45
  # Auxiliary Title Search field. Takes from many fields defined in {AUX_TITLE_TAGS} that contain title-like
@@ -47,10 +47,11 @@ module PennMARC
47
47
  # @param [MARC::Record] record
48
48
  # @return [Array<String>] array of auxiliary title values for search
49
49
  def search_aux(record)
50
- search_aux_values(record: record, title_type: :main, &subfield_not_in?(%w[c 6 8])) +
51
- search_aux_values(record: record, title_type: :related, &subfield_not_in?(%w[s t])) +
52
- search_aux_values(record: record, title_type: :entity, &subfield_in?(%w[t])) +
53
- search_aux_values(record: record, title_type: :note, &subfield_in?(%w[t]))
50
+ values = search_aux_values(record: record, title_type: :main, &subfield_not_in?(%w[c 6 8])) +
51
+ search_aux_values(record: record, title_type: :related, &subfield_not_in?(%w[s t])) +
52
+ search_aux_values(record: record, title_type: :entity, &subfield_in?(%w[t])) +
53
+ search_aux_values(record: record, title_type: :note, &subfield_in?(%w[t]))
54
+ values.uniq
54
55
  end
55
56
 
56
57
  # Journal Title Search field. Takes from {https://www.loc.gov/marc/bibliographic/bd245.html 245} and linked 880.
@@ -61,11 +62,11 @@ module PennMARC
61
62
  def journal_search(record)
62
63
  return [] if not_a_serial?(record)
63
64
 
64
- record.fields(%w[245 880]).filter_map do |field|
65
+ record.fields(%w[245 880]).filter_map { |field|
65
66
  next if field.tag == '880' && subfield_value_not_in?(field, '6', %w[245])
66
67
 
67
68
  join_subfields(field, &subfield_not_in?(%w[c 6 8 h]))
68
- end
69
+ }.uniq
69
70
  end
70
71
 
71
72
  # Auxiliary Journal Title Search field. Takes from many fields defined in {AUX_TITLE_TAGS} that contain title-like
@@ -74,10 +75,11 @@ module PennMARC
74
75
  # @param [MARC::Record] record
75
76
  # @return [Array<String>] auxiliary journal title information for search
76
77
  def journal_search_aux(record)
77
- search_aux_values(record: record, title_type: :main, journal: true, &subfield_not_in?(%w[c 6 8])) +
78
- search_aux_values(record: record, title_type: :related, journal: true, &subfield_not_in?(%w[s t])) +
79
- search_aux_values(record: record, title_type: :entity, journal: true, &subfield_in?(%w[t])) +
80
- search_aux_values(record: record, title_type: :note, journal: true, &subfield_in?(%w[t]))
78
+ values = search_aux_values(record: record, title_type: :main, journal: true, &subfield_not_in?(%w[c 6 8])) +
79
+ search_aux_values(record: record, title_type: :related, journal: true, &subfield_not_in?(%w[s t])) +
80
+ search_aux_values(record: record, title_type: :entity, journal: true, &subfield_in?(%w[t])) +
81
+ search_aux_values(record: record, title_type: :note, journal: true, &subfield_in?(%w[t]))
82
+ values.uniq
81
83
  end
82
84
 
83
85
  # Single-valued Title, for use in headings. Takes the first {https://www.oclc.org/bibformats/en/2xx/245.html 245}
@@ -162,12 +164,13 @@ module PennMARC
162
164
 
163
165
  join_subfields(field, &subfield_not_in?(%w[5 6 8 e w]))
164
166
  end
165
- standardized_titles + record.fields('880').filter_map do |field|
167
+ titles = standardized_titles + record.fields('880').filter_map do |field|
166
168
  next unless subfield_undefined?(field, 'i') ||
167
169
  subfield_value_in?(field, '6', %w[130 240 730])
168
170
 
169
171
  join_subfields field, &subfield_not_in?(%w[5 6 8 e w])
170
172
  end
173
+ titles.uniq
171
174
  end
172
175
 
173
176
  # Other Title for display
@@ -187,11 +190,12 @@ module PennMARC
187
190
 
188
191
  join_subfields(field, &subfield_not_in?(%w[5 6 8]))
189
192
  end
190
- other_titles + record.fields('880').filter_map do |field|
193
+ titles = other_titles + record.fields('880').filter_map do |field|
191
194
  next unless subfield_value_in? field, '6', %w[246 740]
192
195
 
193
196
  join_subfields(field, &subfield_not_in?(%w[5 6 8]))
194
197
  end
198
+ titles.uniq
195
199
  end
196
200
 
197
201
  # Former Title for display.
@@ -204,13 +208,13 @@ module PennMARC
204
208
  # @return [Array<String>] array of former titles
205
209
  def former_show(record)
206
210
  record.fields
207
- .filter_map do |field|
211
+ .filter_map { |field|
208
212
  next unless field.tag == '247' || (field.tag == '880' && subfield_value?(field, '6', /^247/))
209
213
 
210
214
  former_title = join_subfields field, &subfield_not_in?(%w[6 8 e w]) # 6 and 8 are not meaningful for display
211
215
  former_title_append = join_subfields field, &subfield_in?(%w[e w])
212
216
  "#{former_title} #{former_title_append}".strip
213
- end
217
+ }.uniq
214
218
  end
215
219
 
216
220
  private
@@ -588,6 +588,10 @@ finecore:
588
588
  specific_location: Fisher Fine Arts Library - Core Reading Collection
589
589
  library: Fisher Fine Arts Library
590
590
  display: Fine Arts Library - Core Reading Collection
591
+ fineexhib:
592
+ specific_location: Fisher Fine Arts Library - Exhibitions Corridor
593
+ library: Fisher Fine Arts Library
594
+ display: Fine Arts Library - Exhibitions Corridor
591
595
  finelock:
592
596
  specific_location: Fisher Fine Arts Library - Locked Case
593
597
  library:
data/lib/pennmarc/util.rb CHANGED
@@ -14,7 +14,7 @@ module PennMARC
14
14
  end
15
15
 
16
16
  # Join subfields from a field selected based on a provided proc
17
- # @param [MARC::DataField] field
17
+ # @param [MARC::DataField, nil] field
18
18
  # @param [Proc] selector
19
19
  # @return [String]
20
20
  def join_subfields(field, &selector)
@@ -125,6 +125,21 @@ module PennMARC
125
125
  string.sub map[trailer.to_sym], ''
126
126
  end
127
127
 
128
+ # Intelligently append given punctuation to the end of a string
129
+ # @param [Symbol] trailer
130
+ # @param [String] string
131
+ # @return [String]
132
+ def append_trailing(trailer, string)
133
+ return string if string.end_with?('.', '-')
134
+
135
+ map = { semicolon: ';',
136
+ colon: ':',
137
+ slash: '/',
138
+ comma: ',',
139
+ period: '.' }
140
+ string + map[trailer.to_sym]
141
+ end
142
+
128
143
  # MARC 880 field "Alternate Graphic Representation" contains text "linked" to another
129
144
  # field (e.g., 254 [Title]) used as an alternate representation. Often used to hold
130
145
  # translations of title values. A common need is to extract subfields as selected by
@@ -158,7 +173,7 @@ module PennMARC
158
173
  # Returns the non-6,8 subfields from a datafield and its 880 link.
159
174
  # @param [MARC::Record] record
160
175
  # @param [String] tag
161
- # @return [Array] acc
176
+ # @return [Array<String>] values
162
177
  def datafield_and_linked_alternate(record, tag)
163
178
  record.fields(tag).filter_map { |field|
164
179
  join_subfields(field, &subfield_not_in?(%w[6 8]))
@@ -223,7 +238,7 @@ module PennMARC
223
238
  # @param [String] prefix to select from subject field
224
239
  # @return [Array] array of values
225
240
  def prefixed_subject_and_alternate(record, prefix)
226
- record.fields(%w[650 880]).filter_map do |field|
241
+ record.fields(%w[650 880]).filter_map { |field|
227
242
  next unless field.indicator2 == '4'
228
243
 
229
244
  next if field.tag == '880' && subfield_values(field, '6').exclude?('650')
@@ -233,7 +248,7 @@ module PennMARC
233
248
  elements = field.select(&subfield_in?(%w[a])).map { |sf| sf.value.gsub(/^%?#{prefix}/, '') }
234
249
  elements << join_subfields(field, &subfield_not_in?(%w[a 6 8 e w 5]))
235
250
  join_and_squish elements
236
- end
251
+ }.uniq
237
252
  end
238
253
 
239
254
  # Does the given field specify an allowed source code?
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PennMARC
4
- VERSION = '1.0.12'
4
+ VERSION = '1.0.15.pre'
5
5
  end
@@ -10,7 +10,7 @@ describe 'PennMARC::Access' do
10
10
  let(:record) { marc_record fields: [marc_field(tag: tag)] }
11
11
 
12
12
  context 'with enrichment via the Alma publishing process' do
13
- let(:tag) { PennMARC::EnrichedMarc::TAG_ELECTRONIC_INVENTORY }
13
+ let(:tag) { PennMARC::Enriched::Pub::ELEC_INVENTORY_TAG }
14
14
 
15
15
  it 'returns expected access value' do
16
16
  expect(helper.facet(record)).to contain_exactly(PennMARC::Access::ONLINE)
@@ -18,7 +18,7 @@ describe 'PennMARC::Access' do
18
18
  end
19
19
 
20
20
  context 'with enrichment with availability info via the Alma API' do
21
- let(:tag) { PennMARC::EnrichedMarc::AlmaApi::TAG_ELECTRONIC_INVENTORY }
21
+ let(:tag) { PennMARC::Enriched::Api::ELEC_INVENTORY_TAG }
22
22
 
23
23
  it 'returns expected access value' do
24
24
  expect(helper.facet(record)).to contain_exactly(PennMARC::Access::ONLINE)
@@ -30,7 +30,7 @@ describe 'PennMARC::Access' do
30
30
  let(:record) { marc_record fields: [marc_field(tag: tag)] }
31
31
 
32
32
  context 'with enrichment via the Alma publishing process' do
33
- let(:tag) { PennMARC::EnrichedMarc::TAG_HOLDING }
33
+ let(:tag) { PennMARC::Enriched::Pub::PHYS_INVENTORY_TAG }
34
34
 
35
35
  it 'returns expected access value' do
36
36
  expect(helper.facet(record)).to contain_exactly(PennMARC::Access::AT_THE_LIBRARY)
@@ -38,7 +38,7 @@ describe 'PennMARC::Access' do
38
38
  end
39
39
 
40
40
  context 'with enrichment with availability info via the Alma API' do
41
- let(:tag) { PennMARC::EnrichedMarc::AlmaApi::TAG_PHYSICAL_INVENTORY }
41
+ let(:tag) { PennMARC::Enriched::Api::PHYS_INVENTORY_TAG }
42
42
 
43
43
  it 'returns expected access value' do
44
44
  expect(helper.facet(record)).to contain_exactly(PennMARC::Access::AT_THE_LIBRARY)
@@ -48,7 +48,7 @@ describe 'PennMARC::Access' do
48
48
 
49
49
  context 'with a record containing a link to a finding aid (as a handle link)' do
50
50
  let(:record) do
51
- marc_record fields: [marc_field(tag: PennMARC::EnrichedMarc::TAG_HOLDING),
51
+ marc_record fields: [marc_field(tag: PennMARC::Enriched::Pub::PHYS_INVENTORY_TAG),
52
52
  marc_field(tag: '856', subfields: location_and_access_subfields, **indicators)]
53
53
  end
54
54
 
@@ -17,9 +17,9 @@ describe 'PennMARC::Classification' do
17
17
 
18
18
  describe '.facet' do
19
19
  context 'with enrichment via the Alma publishing process' do
20
- let(:tag) { PennMARC::EnrichedMarc::TAG_ITEM }
21
- let(:call_number_type_sf) { PennMARC::EnrichedMarc::SUB_ITEM_CALL_NUMBER_TYPE }
22
- let(:call_number_sf) { PennMARC::EnrichedMarc::SUB_ITEM_CALL_NUMBER }
20
+ let(:tag) { PennMARC::Enriched::Pub::ITEM_TAG }
21
+ let(:call_number_type_sf) { PennMARC::Enriched::Pub::ITEM_CALL_NUMBER_TYPE }
22
+ let(:call_number_sf) { PennMARC::Enriched::Pub::ITEM_CALL_NUMBER }
23
23
 
24
24
  it 'returns expected values' do
25
25
  expect(helper.facet(record)).to contain_exactly('T - Technology', '600 - Technology',
@@ -28,9 +28,9 @@ describe 'PennMARC::Classification' do
28
28
  end
29
29
 
30
30
  context 'with enrichment with availability info via Alma Api' do
31
- let(:tag) { PennMARC::EnrichedMarc::AlmaApi::TAG_PHYSICAL_INVENTORY }
32
- let(:call_number_type_sf) { PennMARC::EnrichedMarc::AlmaApi::SUB_PHYSICAL_CALL_NUMBER_TYPE }
33
- let(:call_number_sf) { PennMARC::EnrichedMarc::AlmaApi::SUB_PHYSICAL_CALL_NUMBER }
31
+ let(:tag) { PennMARC::Enriched::Api::PHYS_INVENTORY_TAG }
32
+ let(:call_number_type_sf) { PennMARC::Enriched::Api::PHYS_CALL_NUMBER_TYPE }
33
+ let(:call_number_sf) { PennMARC::Enriched::Api::PHYS_CALL_NUMBER }
34
34
 
35
35
  it 'returns expected values' do
36
36
  expect(helper.facet(record)).to contain_exactly('T - Technology', '600 - Technology',
@@ -17,11 +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 [
20
+ expect(helper.search(record, relator_map: mapping)).to contain_exactly(
21
21
  'Name Surname http://cool.uri/12345 author 1900-2000.',
22
22
  'Surname, Name http://cool.uri/12345 author 1900-2000.',
23
23
  'Alternative Surname'
24
- ]
24
+ )
25
25
  end
26
26
  end
27
27
 
@@ -32,8 +32,33 @@ describe 'PennMARC::Creator' do
32
32
  end
33
33
 
34
34
  it 'contains the expected search field values for a corporate author work' do
35
- expect(helper.search(record, relator_map: mapping)).to eq ['Group of People Annual Meeting Author.',
36
- 'Alt. Group Name Alt. Annual Meeting']
35
+ expect(helper.search(record, relator_map: mapping)).to contain_exactly(
36
+ 'Group of People Annual Meeting, Author.',
37
+ 'Alt. Group Name Alt. Annual Meeting'
38
+ )
39
+ end
40
+ end
41
+ end
42
+
43
+ describe '.search_aux' do
44
+ let(:record) { marc_record fields: fields }
45
+
46
+ context 'with a record that has an added name in the 7xx field' do
47
+ let(:fields) do
48
+ [marc_field(tag: '100', subfields: { a: 'Author', c: 'Fancy', d: 'active 24th century AD', '4': 'aut' }),
49
+ marc_field(tag: '700', subfields: { a: 'Author, Added' }),
50
+ marc_field(tag: '880', subfields: { '6': '100', a: 'Alt Author', c: 'Alt Fanciness' }),
51
+ marc_field(tag: '880', subfields: { '6': '700', a: 'Alt Added Author' })]
52
+ end
53
+
54
+ it 'contains the expected search_aux field values for a single author work' do
55
+ expect(helper.search_aux(record, relator_map: mapping)).to contain_exactly(
56
+ 'Author Fancy active 24th century AD, Author.',
57
+ 'Author, Added.',
58
+ 'Added Author.',
59
+ 'Alt Author Alt Fanciness',
60
+ 'Alt Added Author'
61
+ )
37
62
  end
38
63
  end
39
64
  end
@@ -187,6 +212,18 @@ describe 'PennMARC::Creator' do
187
212
  end
188
213
  end
189
214
 
215
+ describe '.conference_search' do
216
+ let(:record) do
217
+ marc_record fields: [
218
+ marc_field(tag: '111', subfields: { a: 'MARC History Symposium', c: 'Moscow', '4': 'aut' })
219
+ ]
220
+ end
221
+
222
+ it 'returns conference name information for searching without relator value' do
223
+ expect(helper.conference_search(record)).to eq ['MARC History Symposium Moscow']
224
+ end
225
+ end
226
+
190
227
  describe '.contributor_show' do
191
228
  let(:record) do
192
229
  marc_record fields: [
@@ -217,7 +254,4 @@ describe 'PennMARC::Creator' do
217
254
  )
218
255
  end
219
256
  end
220
-
221
- # describe '.conference_search'
222
- # describe '.search_aux'
223
257
  end
@@ -68,9 +68,9 @@ describe 'PennMARC::Format' do
68
68
  context 'with API enriched fields' do
69
69
  let(:record) do
70
70
  marc_record fields: [
71
- marc_field(tag: PennMARC::EnrichedMarc::AlmaApi::TAG_PHYSICAL_INVENTORY, subfields: {
71
+ marc_field(tag: PennMARC::Enriched::Api::PHYS_INVENTORY_TAG, subfields: {
72
72
  :h => 'AB123',
73
- PennMARC::EnrichedMarc::AlmaApi::SUB_PHYSICAL_CALL_NUMBER_TYPE => '.456 Microfilm'
73
+ PennMARC::Enriched::Api::PHYS_CALL_NUMBER_TYPE => '.456 Microfilm'
74
74
  })
75
75
  ]
76
76
  end
@@ -83,9 +83,9 @@ describe 'PennMARC::Format' do
83
83
  context 'with publishing enriched fields' do
84
84
  let(:record) do
85
85
  marc_record fields: [
86
- marc_field(tag: PennMARC::EnrichedMarc::TAG_HOLDING,
86
+ marc_field(tag: PennMARC::Enriched::Pub::PHYS_INVENTORY_TAG,
87
87
  subfields: { :h => 'AB123',
88
- PennMARC::EnrichedMarc::SUB_ITEM_CALL_NUMBER_TYPE => '.456 Microfilm' })
88
+ PennMARC::Enriched::Pub::ITEM_CALL_NUMBER_TYPE => '.456 Microfilm' })
89
89
  ]
90
90
  end
91
91
 
@@ -0,0 +1,129 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe 'PennMARC::Inventory' do
4
+ include MarcSpecHelpers
5
+
6
+ let(:helper) { PennMARC::Inventory }
7
+ let(:record) do
8
+ marc_record fields: fields
9
+ end
10
+
11
+ describe 'physical' do
12
+ let(:fields) do
13
+ [marc_field(tag: mapper::PHYS_INVENTORY_TAG,
14
+ subfields: subfields)]
15
+ end
16
+
17
+ context 'with API enrichment fields' do
18
+ let(:mapper) { PennMARC::Enriched::Api }
19
+ let(:subfields) do
20
+ { mapper::PHYS_CALL_NUMBER => 'AB123.4',
21
+ mapper::PHYS_HOLDING_ID => '123456789',
22
+ mapper::PHYS_LOCATION_CODE => 'vanpelt',
23
+ mapper::PHYS_LOCATION_NAME => 'Van Pelt Library',
24
+ mapper::PHYS_PRIORITY => '1' }
25
+ end
26
+
27
+ it 'returns expected array of hash values' do
28
+ expect(helper.physical(record)).to contain_exactly(
29
+ { call_num: 'AB123.4', holding_id: '123456789', location_code: 'vanpelt',
30
+ location_name: 'Van Pelt Library', priority: '1' }
31
+ )
32
+ end
33
+ end
34
+
35
+ context 'with Pub enrichment fields' do
36
+ let(:mapper) { PennMARC::Enriched::Pub }
37
+ let(:subfields) do
38
+ { mapper::HOLDING_CLASSIFICATION_PART => 'AB123',
39
+ mapper::HOLDING_ITEM_PART => '.4',
40
+ mapper::PHYS_HOLDING_ID => '123456789',
41
+ mapper::PHYS_LOCATION_CODE => 'vanpelt',
42
+ mapper::PHYS_LOCATION_NAME => 'Van Pelt Library' }
43
+ end
44
+
45
+ it 'returns expected array of hash values' do
46
+ expect(helper.physical(record)).to contain_exactly(
47
+ { call_num: 'AB123.4', holding_id: '123456789', location_code: 'vanpelt',
48
+ location_name: 'Van Pelt Library', priority: nil }
49
+ )
50
+ end
51
+ end
52
+ end
53
+
54
+ describe 'electronic' do
55
+ let(:fields) do
56
+ [marc_field(tag: mapper::ELEC_INVENTORY_TAG,
57
+ subfields: subfields)]
58
+ end
59
+ let(:subfields) do
60
+ { mapper::ELEC_PORTFOLIO_ID => '234567890',
61
+ mapper::ELEC_SERVICE_URL => 'https://www.iwish.com',
62
+ mapper::ELEC_COLLECTION_NAME => 'All Articles Repo',
63
+ mapper::ELEC_COVERAGE_STMT => 'All time',
64
+ mapper::ELEC_PUBLIC_NOTE => 'Portfolio public note' }
65
+ end
66
+
67
+ context 'with API enrichment fields' do
68
+ let(:mapper) { PennMARC::Enriched::Api }
69
+
70
+ it 'returns expected array of hash values' do
71
+ expect(helper.electronic(record)).to contain_exactly(
72
+ { portfolio_id: '234567890', url: 'https://www.iwish.com', collection_name: 'All Articles Repo',
73
+ coverage: 'All time', note: 'Portfolio public note' }
74
+ )
75
+ end
76
+ end
77
+
78
+ context 'with Pub enrichment fields' do
79
+ let(:mapper) { PennMARC::Enriched::Pub }
80
+
81
+ it 'returns expected array of hash values' do
82
+ expect(helper.electronic(record)).to contain_exactly(
83
+ { portfolio_id: '234567890', url: 'https://www.iwish.com', collection_name: 'All Articles Repo',
84
+ coverage: 'All time', note: 'Portfolio public note' }
85
+ )
86
+ end
87
+ end
88
+ end
89
+
90
+ describe 'electronic_portfolio_count' do
91
+ let(:fields) { [marc_field(tag: inventory_tag), marc_field(tag: inventory_tag)] }
92
+
93
+ context 'with API enrichment fields' do
94
+ let(:inventory_tag) { PennMARC::Enriched::Api::ELEC_INVENTORY_TAG }
95
+
96
+ it 'returns the correct count' do
97
+ expect(helper.electronic_portfolio_count(record)).to eq 2
98
+ end
99
+ end
100
+
101
+ context 'with Pub enrichment fields' do
102
+ let(:inventory_tag) { PennMARC::Enriched::Pub::ELEC_INVENTORY_TAG }
103
+
104
+ it 'returns the correct count' do
105
+ expect(helper.electronic_portfolio_count(record)).to eq 2
106
+ end
107
+ end
108
+ end
109
+
110
+ describe 'physical_holding_count' do
111
+ let(:fields) { [marc_field(tag: inventory_tag), marc_field(tag: inventory_tag)] }
112
+
113
+ context 'with API enrichment fields' do
114
+ let(:inventory_tag) { PennMARC::Enriched::Api::PHYS_INVENTORY_TAG }
115
+
116
+ it 'returns the correct count' do
117
+ expect(helper.physical_holding_count(record)).to eq 2
118
+ end
119
+ end
120
+
121
+ context 'with Pub enrichment fields' do
122
+ let(:inventory_tag) { PennMARC::Enriched::Pub::PHYS_INVENTORY_TAG }
123
+
124
+ it 'returns the correct count' do
125
+ expect(helper.physical_holding_count(record)).to eq 2
126
+ end
127
+ end
128
+ end
129
+ end
@@ -4,11 +4,15 @@ describe 'PennMARC::Location' do
4
4
  include MarcSpecHelpers
5
5
 
6
6
  let(:helper) { PennMARC::Location }
7
+ let(:enriched_marc) { PennMARC::Enriched }
7
8
  let(:mapping) { location_map }
8
9
 
9
10
  describe 'location' do
10
11
  context "with only 'itm' field present" do
11
- let(:record) { marc_record(fields: [marc_field(tag: 'itm', subfields: { g: 'stor' })]) }
12
+ let(:record) do
13
+ marc_record(fields: [marc_field(tag: enriched_marc::Pub::ITEM_TAG,
14
+ subfields: { enriched_marc::Pub::ITEM_CURRENT_LOCATION => 'stor' })])
15
+ end
12
16
 
13
17
  it 'returns expected value' do
14
18
  expect(helper.location(record: record, location_map: mapping,
@@ -19,7 +23,10 @@ describe 'PennMARC::Location' do
19
23
  end
20
24
 
21
25
  context "with only 'hld' field present" do
22
- let(:record) { marc_record(fields: [marc_field(tag: 'hld', subfields: { c: 'stor' })]) }
26
+ let(:record) do
27
+ marc_record(fields: [marc_field(tag: enriched_marc::Pub::PHYS_INVENTORY_TAG,
28
+ subfields: { enriched_marc::Pub::PHYS_LOCATION_CODE => 'stor' })])
29
+ end
23
30
 
24
31
  it 'returns expected value' do
25
32
  expect(helper.location(record: record, location_map: mapping,
@@ -29,10 +36,12 @@ describe 'PennMARC::Location' do
29
36
  end
30
37
  end
31
38
 
32
- context "with both 'hld' and 'itm' fields present" do
39
+ context 'with both holding and item tag fields present=' do
33
40
  let(:record) do
34
- marc_record(fields: [marc_field(tag: 'itm', subfields: { g: 'stor' }),
35
- marc_field(tag: 'hld', subfields: { c: 'dent' })])
41
+ marc_record(fields: [marc_field(tag: enriched_marc::Pub::ITEM_TAG,
42
+ subfields: { enriched_marc::Pub::ITEM_CURRENT_LOCATION => 'stor' }),
43
+ marc_field(tag: enriched_marc::Pub::PHYS_INVENTORY_TAG,
44
+ subfields: { enriched_marc::Pub::PHYS_LOCATION_CODE => 'dent' })])
36
45
  end
37
46
 
38
47
  it 'returns item location' do
@@ -42,7 +51,7 @@ describe 'PennMARC::Location' do
42
51
  end
43
52
 
44
53
  context 'with multiple library locations' do
45
- let(:record) { marc_record(fields: [marc_field(tag: 'itm', subfields: { g: %w[dent] })]) }
54
+ let(:record) { marc_record(fields: [marc_field(tag: enriched_marc::Pub::ITEM_TAG, subfields: { g: %w[dent] })]) }
46
55
 
47
56
  it 'returns expected value' do
48
57
  expect(helper.location(record: record, location_map: mapping,
@@ -60,17 +69,26 @@ describe 'PennMARC::Location' do
60
69
  end
61
70
 
62
71
  context 'with electronic inventory tag' do
63
- let(:record) { marc_record(fields: [marc_field(tag: 'itm', subfields: { g: 'stor' }), marc_field(tag: 'prt')]) }
72
+ let(:record) do
73
+ marc_record(fields: [marc_field(tag: enriched_marc::Pub::ITEM_TAG,
74
+ subfields: { enriched_marc::Pub::ITEM_CURRENT_LOCATION => 'stor' }),
75
+ marc_field(tag: enriched_marc::Pub::ELEC_INVENTORY_TAG)])
76
+ end
64
77
 
65
78
  it 'returns expected value' do
66
79
  expect(helper.location(record: record, location_map: mapping,
67
- display_value: :library)).to contain_exactly('LIBRA', 'Online library')
80
+ display_value: :library)).to contain_exactly('LIBRA', helper::ONLINE_LIBRARY)
68
81
  end
69
82
  end
70
83
 
71
84
  context 'with AVA fields' do
72
85
  let(:record) do
73
- marc_record(fields: [marc_field(tag: 'AVA', subfields: { b: 'Libra', c: 'LIBRA', j: 'stor' })])
86
+ marc_record(fields: [marc_field(tag: enriched_marc::Api::PHYS_INVENTORY_TAG,
87
+ subfields: {
88
+ enriched_marc::Api::PHYS_LIBRARY_CODE => 'Libra',
89
+ enriched_marc::Api::PHYS_LOCATION_NAME => 'LIBRA',
90
+ enriched_marc::Api::PHYS_LOCATION_CODE => 'stor'
91
+ })])
74
92
  end
75
93
 
76
94
  it 'returns expected values' do
@@ -79,5 +97,18 @@ describe 'PennMARC::Location' do
79
97
  )
80
98
  end
81
99
  end
100
+
101
+ context 'with AVE fields' do
102
+ let(:record) do
103
+ marc_record(fields: [marc_field(tag: enriched_marc::Api::ELEC_INVENTORY_TAG,
104
+ subfields: { enriched_marc::Api::ELEC_COLLECTION_NAME => 'Nature' })])
105
+ end
106
+
107
+ it 'returns expected values' do
108
+ expect(helper.location(record: record, location_map: mapping, display_value: :library)).to(
109
+ contain_exactly(helper::ONLINE_LIBRARY)
110
+ )
111
+ end
112
+ end
82
113
  end
83
114
  end