pennmarc 0.0.2 → 1.0.0

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/.rubocop.yml +4 -0
  3. data/.rubocop_todo.yml +151 -0
  4. data/Gemfile +1 -1
  5. data/lib/pennmarc/helpers/creator.rb +47 -13
  6. data/lib/pennmarc/helpers/database.rb +8 -8
  7. data/lib/pennmarc/helpers/date.rb +16 -15
  8. data/lib/pennmarc/helpers/edition.rb +14 -11
  9. data/lib/pennmarc/helpers/format.rb +16 -5
  10. data/lib/pennmarc/helpers/genre.rb +12 -11
  11. data/lib/pennmarc/helpers/identifier.rb +16 -7
  12. data/lib/pennmarc/helpers/language.rb +1 -1
  13. data/lib/pennmarc/helpers/link.rb +6 -0
  14. data/lib/pennmarc/helpers/location.rb +14 -14
  15. data/lib/pennmarc/helpers/note.rb +52 -2
  16. data/lib/pennmarc/helpers/relation.rb +9 -9
  17. data/lib/pennmarc/helpers/series.rb +182 -85
  18. data/lib/pennmarc/helpers/subject.rb +11 -11
  19. data/lib/pennmarc/helpers/title.rb +1 -1
  20. data/lib/pennmarc/parser.rb +2 -99
  21. data/lib/pennmarc/util.rb +11 -11
  22. data/pennmarc.gemspec +2 -2
  23. data/spec/lib/pennmarc/helpers/citation_spec.rb +1 -2
  24. data/spec/lib/pennmarc/helpers/creator_spec.rb +46 -11
  25. data/spec/lib/pennmarc/helpers/date_spec.rb +5 -5
  26. data/spec/lib/pennmarc/helpers/edition_spec.rb +1 -4
  27. data/spec/lib/pennmarc/helpers/format_spec.rb +29 -9
  28. data/spec/lib/pennmarc/helpers/genre_spec.rb +3 -3
  29. data/spec/lib/pennmarc/helpers/identifer_spec.rb +15 -0
  30. data/spec/lib/pennmarc/helpers/location_spec.rb +9 -8
  31. data/spec/lib/pennmarc/helpers/note_spec.rb +67 -2
  32. data/spec/lib/pennmarc/helpers/series_spec.rb +54 -0
  33. data/spec/lib/pennmarc/helpers/subject_spec.rb +8 -8
  34. data/spec/lib/pennmarc/helpers/title_spec.rb +3 -1
  35. data/spec/lib/pennmarc/marc_util_spec.rb +9 -8
  36. data/spec/lib/pennmarc/parser_spec.rb +2 -2
  37. data/spec/spec_helper.rb +1 -1
  38. metadata +7 -17
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b68bae786cc1cd9bcd1bb53e401be81bc3a97d4bb4319c6b37f9089898721424
4
- data.tar.gz: ca840e625b1fbfe4e8e9cd9ef042eb2f8afbc8323e620b8fcb7f190d2e65c71c
3
+ metadata.gz: 84864756f38d54ec58b75b355931ba9b4310f7f880245c2c437ecebb63fee447
4
+ data.tar.gz: ee807c262dc0f5e2117b779b44a47cf10012c8e019340a789ac4c60d21223842
5
5
  SHA512:
6
- metadata.gz: 5d7c2a945285aec3959c3594414f937005ed981c4ed0d7c6ffb567456f7c25ec7a08dfb06fb0cb8316b482743637724b756d348596946e909087a7ad51d4e658
7
- data.tar.gz: e542bb11f7174cbfe3bb1f55aac1ac769a7fd004dc828354e09ac52911ffee680f3782189181d0d28617e2db9557c1cf654ae40f3c3f9e467b2e11657d9a33a2
6
+ metadata.gz: fee3c852594dcdbb871e093f0bd45efb4043e14bfe323f6da3d48bab3dc75eb58f968b26a24e3ae786742c112f3a9ebf7ae43fb1688f33011d4b89c4ded7af1c
7
+ data.tar.gz: 1192019b7f5b79c90a2d68fa46d7aa6ce7b8a2cea55f78072db3191401a4109c8d96fc5eb47ff86d05805a4cabb3409d4d90062c57ff96bdcbd9d987037160fd
data/.rubocop.yml ADDED
@@ -0,0 +1,4 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ inherit_gem:
4
+ upennlib-rubocop: upennlib_rubocop_defaults.yml
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,151 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config --auto-gen-only-exclude --exclude-limit 10000`
3
+ # on 2023-07-28 16:23:59 UTC using RuboCop version 1.51.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 21
10
+ # Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes, Max.
11
+ Metrics/AbcSize:
12
+ Exclude:
13
+ - 'lib/pennmarc/helpers/creator.rb'
14
+ - 'lib/pennmarc/helpers/edition.rb'
15
+ - 'lib/pennmarc/helpers/format.rb'
16
+ - 'lib/pennmarc/helpers/genre.rb'
17
+ - 'lib/pennmarc/helpers/location.rb'
18
+ - 'lib/pennmarc/helpers/note.rb'
19
+ - 'lib/pennmarc/helpers/production.rb'
20
+ - 'lib/pennmarc/helpers/relation.rb'
21
+ - 'lib/pennmarc/helpers/series.rb'
22
+ - 'lib/pennmarc/helpers/subject.rb'
23
+ - 'lib/pennmarc/helpers/title.rb'
24
+ - 'lib/pennmarc/util.rb'
25
+
26
+ # Offense count: 5
27
+ # Configuration parameters: CountComments, Max, CountAsOne.
28
+ Metrics/ClassLength:
29
+ Exclude:
30
+ - 'lib/pennmarc/helpers/creator.rb'
31
+ - 'lib/pennmarc/helpers/format.rb'
32
+ - 'lib/pennmarc/helpers/series.rb'
33
+ - 'lib/pennmarc/helpers/subject.rb'
34
+ - 'lib/pennmarc/helpers/title.rb'
35
+
36
+ # Offense count: 18
37
+ # Configuration parameters: AllowedMethods, AllowedPatterns, Max.
38
+ Metrics/CyclomaticComplexity:
39
+ Exclude:
40
+ - 'lib/pennmarc/helpers/creator.rb'
41
+ - 'lib/pennmarc/helpers/database.rb'
42
+ - 'lib/pennmarc/helpers/edition.rb'
43
+ - 'lib/pennmarc/helpers/format.rb'
44
+ - 'lib/pennmarc/helpers/genre.rb'
45
+ - 'lib/pennmarc/helpers/note.rb'
46
+ - 'lib/pennmarc/helpers/production.rb'
47
+ - 'lib/pennmarc/helpers/relation.rb'
48
+ - 'lib/pennmarc/helpers/series.rb'
49
+ - 'lib/pennmarc/helpers/subject.rb'
50
+ - 'lib/pennmarc/helpers/title.rb'
51
+ - 'lib/pennmarc/util.rb'
52
+
53
+ # Offense count: 22
54
+ # Configuration parameters: CountComments, Max, CountAsOne, AllowedMethods, AllowedPatterns.
55
+ Metrics/MethodLength:
56
+ Exclude:
57
+ - 'lib/pennmarc/helpers/creator.rb'
58
+ - 'lib/pennmarc/helpers/date.rb'
59
+ - 'lib/pennmarc/helpers/edition.rb'
60
+ - 'lib/pennmarc/helpers/format.rb'
61
+ - 'lib/pennmarc/helpers/location.rb'
62
+ - 'lib/pennmarc/helpers/note.rb'
63
+ - 'lib/pennmarc/helpers/production.rb'
64
+ - 'lib/pennmarc/helpers/relation.rb'
65
+ - 'lib/pennmarc/helpers/series.rb'
66
+ - 'lib/pennmarc/helpers/subject.rb'
67
+ - 'lib/pennmarc/helpers/title.rb'
68
+
69
+ # Offense count: 1
70
+ # Configuration parameters: CountComments, Max, CountAsOne.
71
+ Metrics/ModuleLength:
72
+ Exclude:
73
+ - 'lib/pennmarc/util.rb'
74
+
75
+ # Offense count: 12
76
+ # Configuration parameters: AllowedMethods, AllowedPatterns, Max.
77
+ Metrics/PerceivedComplexity:
78
+ Exclude:
79
+ - 'lib/pennmarc/helpers/creator.rb'
80
+ - 'lib/pennmarc/helpers/edition.rb'
81
+ - 'lib/pennmarc/helpers/format.rb'
82
+ - 'lib/pennmarc/helpers/genre.rb'
83
+ - 'lib/pennmarc/helpers/note.rb'
84
+ - 'lib/pennmarc/helpers/production.rb'
85
+ - 'lib/pennmarc/helpers/series.rb'
86
+ - 'lib/pennmarc/helpers/title.rb'
87
+ - 'lib/pennmarc/util.rb'
88
+
89
+ # Offense count: 1
90
+ # Configuration parameters: NamePrefix, ForbiddenPrefixes, AllowedMethods, MethodDefinitionMacros.
91
+ # NamePrefix: is_, has_, have_
92
+ # ForbiddenPrefixes: is_, has_, have_
93
+ # AllowedMethods: is_a?
94
+ # MethodDefinitionMacros: define_method, define_singleton_method
95
+ Naming/PredicateName:
96
+ Exclude:
97
+ - 'lib/pennmarc/helpers/relation.rb'
98
+
99
+ # Offense count: 2
100
+ # Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers, AllowedPatterns.
101
+ # SupportedStyles: snake_case, normalcase, non_integer
102
+ # AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339, x86_64
103
+ Naming/VariableNumber:
104
+ Exclude:
105
+ - 'lib/pennmarc/util.rb'
106
+
107
+ # Offense count: 7
108
+ # Configuration parameters: MinSize.
109
+ Performance/CollectionLiteralInLoop:
110
+ Exclude:
111
+ - 'lib/pennmarc/helpers/creator.rb'
112
+ - 'lib/pennmarc/helpers/edition.rb'
113
+ - 'lib/pennmarc/helpers/series.rb'
114
+
115
+ # Offense count: 6
116
+ # Configuration parameters: Max, CountAsOne.
117
+ RSpec/ExampleLength:
118
+ Exclude:
119
+ - 'spec/lib/pennmarc/helpers/creator_spec.rb'
120
+ - 'spec/lib/pennmarc/helpers/note_spec.rb'
121
+ - 'spec/lib/pennmarc/helpers/production_spec.rb'
122
+ - 'spec/lib/pennmarc/marc_util_spec.rb'
123
+
124
+ # Offense count: 1
125
+ # Configuration parameters: Include, CustomTransform, IgnoreMethods, SpecSuffixOnly.
126
+ # Include: **/*_spec*rb*, **/spec/**/*
127
+ RSpec/FilePath:
128
+ Exclude:
129
+ - 'spec/lib/pennmarc/parser_spec.rb'
130
+
131
+ # Offense count: 4
132
+ # Configuration parameters: Max, AllowedGroups.
133
+ RSpec/NestedGroups:
134
+ Exclude:
135
+ - 'spec/lib/pennmarc/helpers/format_spec.rb'
136
+
137
+ # Offense count: 2
138
+ # This cop supports unsafe autocorrection (--autocorrect-all).
139
+ # Configuration parameters: Include.
140
+ # Include: app/**/*.rb, config/**/*.rb, db/**/*.rb, lib/**/*.rb
141
+ Rails/Output:
142
+ Exclude:
143
+ - 'lib/pennmarc/helpers/date.rb'
144
+
145
+ # Offense count: 1
146
+ # This cop supports safe autocorrection (--autocorrect).
147
+ # Configuration parameters: Max, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
148
+ # URISchemes: http, https
149
+ Layout/LineLength:
150
+ Exclude:
151
+ - 'lib/pennmarc/helpers/subject.rb'
data/Gemfile CHANGED
@@ -7,6 +7,7 @@ gem 'library_stdnums', '~> 1.6'
7
7
  gem 'marc', '~> 1.2'
8
8
  gem 'nokogiri', '~> 1.15'
9
9
  gem 'rake', '~> 13.0'
10
+ gem 'upennlib-rubocop', require: false
10
11
 
11
12
  group :test, :development do
12
13
  gem 'rspec', '~> 3.12'
@@ -17,7 +18,6 @@ group :test do
17
18
  end
18
19
 
19
20
  group :development do
20
- gem 'upennlib-rubocop', require: false
21
21
  gem 'webrick', '~> 1.8'
22
22
  gem 'yard', '~> 0.9'
23
23
  end
@@ -26,7 +26,7 @@ module PennMARC
26
26
  # @param [MARC::Record] record
27
27
  # @param [Hash] relator_mapping
28
28
  # @return [Array<String>] array of author/creator values for indexing
29
- def search(record, relator_mapping)
29
+ def search(record, relator_mapping = relator_map)
30
30
  acc = record.fields(TAGS).map do |field|
31
31
  pieces = field.filter_map do |sf|
32
32
  if sf.code == 'a'
@@ -41,7 +41,7 @@ module PennMARC
41
41
  end
42
42
  end
43
43
  value = join_and_squish(pieces)
44
- if value.end_with?('.') || value.end_with?('-')
44
+ if value.end_with?('.', '-')
45
45
  value
46
46
  else
47
47
  "#{value}."
@@ -60,7 +60,7 @@ module PennMARC
60
60
  end
61
61
  end
62
62
  value = join_and_squish(pieces)
63
- if value.end_with?('.') || value.end_with?('-')
63
+ if value.end_with?('.', '-')
64
64
  value
65
65
  else
66
66
  "#{value}."
@@ -69,9 +69,9 @@ module PennMARC
69
69
  acc += record.fields(%w[880]).filter_map do |field|
70
70
  next unless field.any? { |sf| sf.code == '6' && sf.value.in?(%w[100 110]) }
71
71
 
72
- suba = field.find_all(&subfield_in?(%w[a])).map do |sf|
72
+ suba = field.find_all(&subfield_in?(%w[a])).map { |sf|
73
73
  convert_name_order(sf.value)
74
- end.first
74
+ }.first
75
75
  oth = join_and_squish(field.find_all(&subfield_not_in?(%w[6 8 a t])).map(&:value))
76
76
  join_and_squish [suba, oth]
77
77
  end
@@ -90,7 +90,7 @@ module PennMARC
90
90
  # @param [MARC::Record] record
91
91
  # @param [Hash] relator_mapping
92
92
  # @return [Array<String>] array of author/creator values for display
93
- def values(record, relator_mapping)
93
+ def values(record, relator_mapping = relator_map)
94
94
  record.fields(TAGS).map do |field|
95
95
  name_from_main_entry(field, relator_mapping)
96
96
  end
@@ -135,7 +135,7 @@ module PennMARC
135
135
  }
136
136
  source_map.flat_map do |field_num, subfields|
137
137
  record.fields(field_num.to_s).map do |field|
138
- trim_punctuation(join_subfields(field, &subfield_in?(subfields.split(''))))
138
+ trim_punctuation(join_subfields(field, &subfield_in?(subfields.chars)))
139
139
  end
140
140
  end
141
141
  end
@@ -143,11 +143,11 @@ module PennMARC
143
143
  # Conference for display, intended for results display
144
144
  # @note ported from get_conference_values
145
145
  # @param [MARC::Record] record
146
- # @param [Hash] relator_map
146
+ # @param [Hash] relator_mapping
147
147
  # @return [Array<String>] array of conference values
148
- def conference_show(record, relator_map)
148
+ def conference_show(record, relator_mapping = relator_map)
149
149
  record.fields('111').filter_map do |field|
150
- name_from_main_entry field, relator_map
150
+ name_from_main_entry field, relator_mapping
151
151
  end
152
152
  end
153
153
 
@@ -183,6 +183,40 @@ module PennMARC
183
183
  # @note see get_conference_search_values
184
184
  def conference_search(record); end
185
185
 
186
+ # Retrieve contributor values for display from fields {https://www.oclc.org/bibformats/en/7xx/700.html 700}
187
+ # and {https://www.oclc.org/bibformats/en/7xx/710.html 710} and their linked alternates. Joins subfields
188
+ # 'a', 'b', 'c', 'd', 'j', and 'q'. Then appends resulting string with joined subfields 'e', 'u', '3', and '4'.
189
+ # @note legacy version returns array of hash objects including data for display link
190
+ # @param [MARC::Record] record
191
+ # @ param [Hash] relator_mapping
192
+ # @return [Array<String>]
193
+ def contributor_show(record, relator_mapping = relator_map)
194
+ contributors = record.fields(%w[700 710]).filter_map do |field|
195
+ next unless ['', ' ', '0'].member?(field.indicator2)
196
+ next if subfield_defined? field, 'i'
197
+
198
+ contributor = join_subfields(field, &subfield_in?(%w[a b c d j q]))
199
+ contributor_append = field.filter_map { |subfield|
200
+ next unless %w[e u 3 4].member?(subfield.code)
201
+
202
+ if subfield.code == '4'
203
+ ", #{translate_relator(subfield.value, relator_mapping)}"
204
+ else
205
+ " #{subfield.value}"
206
+ end
207
+ }.join
208
+ "#{contributor} #{contributor_append}".squish
209
+ end
210
+ contributors + record.fields('880').filter_map do |field|
211
+ next unless subfield_value_in?(field, '6', %w[700 710])
212
+ next if subfield_defined?(field, 'i')
213
+
214
+ contributor = join_subfields(field, &subfield_in?(%w[a b c d j q]))
215
+ contributor_append = join_subfields(field, &subfield_in?(%w[e u 3]))
216
+ "#{contributor} #{contributor_append}".squish
217
+ end
218
+ end
219
+
186
220
  private
187
221
 
188
222
  # Trim punctuation method extracted from Traject macro, to ensure consistent output
@@ -209,7 +243,7 @@ module PennMARC
209
243
  # @param [MARC::Field] field
210
244
  # @return [String] joined subfield values for value from field
211
245
  def name_from_main_entry(field, mapping)
212
- s = field.filter_map do |sf|
246
+ s = field.filter_map { |sf|
213
247
  if %w[0 1 4 6 8].exclude?(sf.code)
214
248
  " #{sf.value}"
215
249
  elsif sf.code == '4'
@@ -218,8 +252,8 @@ module PennMARC
218
252
 
219
253
  ", #{relator}"
220
254
  end
221
- end.join
222
- (s + (!%w[. -].member?(s.last) ? '.' : '')).squish
255
+ }.join
256
+ (s + (%w[. -].member?(s.last) ? '' : '.')).squish
223
257
  end
224
258
 
225
259
  # Convert "Lastname, First" to "First Lastname"
@@ -21,7 +21,7 @@ module PennMARC
21
21
  def type(record)
22
22
  record.fields('944').filter_map do |field|
23
23
  # skip unless specified database format type present
24
- next unless subfield_value?(field, 'a', /#{DATABASES_FACET_VALUE}/)
24
+ next unless subfield_value?(field, 'a', /#{DATABASES_FACET_VALUE}/o)
25
25
 
26
26
  type = field.find { |subfield| subfield.code == 'b' }
27
27
  type&.value
@@ -39,7 +39,7 @@ module PennMARC
39
39
 
40
40
  record.fields('943').filter_map do |field|
41
41
  # skip unless Community of Interest code is in subfield '2'
42
- next unless subfield_value?(field, '2', /#{COI_CODE}/)
42
+ next unless subfield_value?(field, '2', /#{COI_CODE}/o)
43
43
 
44
44
  category = field.find { |subfield| subfield.code == 'a' }
45
45
  category&.value
@@ -60,17 +60,17 @@ module PennMARC
60
60
 
61
61
  record.fields('943').filter_map do |field|
62
62
  # skip unless Community of Interest code is in subfield '2'
63
- next unless subfield_value?(field, '2', /#{COI_CODE}/)
63
+ next unless subfield_value?(field, '2', /#{COI_CODE}/o)
64
64
 
65
65
  category = field.find { |subfield| subfield.code == 'a' }
66
66
 
67
- # skip unless category is present
68
- next unless category.present?
67
+ # skip if category is blank
68
+ next if category.blank?
69
69
 
70
70
  subcategory = field.find { |subfield| subfield.code == 'b' }
71
71
 
72
- # skip unless subcategory is present
73
- next unless subcategory.present?
72
+ # skip if subcategory is blank
73
+ next if subcategory.blank?
74
74
 
75
75
  "#{category.value}--#{subcategory.value}"
76
76
  end
@@ -82,7 +82,7 @@ module PennMARC
82
82
  # @param [Marc::Record]
83
83
  # @return [TrueClass, FalseClass]
84
84
  def curated_db?(record)
85
- record.fields('944').any? { |field| subfield_value?(field, 'a', /#{DATABASES_FACET_VALUE}/) }
85
+ record.fields('944').any? { |field| subfield_value?(field, 'a', /#{DATABASES_FACET_VALUE}/o) }
86
86
  end
87
87
  end
88
88
  end
@@ -10,13 +10,13 @@ module PennMARC
10
10
  # @param [MARC::Record] record
11
11
  # @return [DateTime, nil] The publication date, or nil if date found in record is invalid
12
12
  def publication(record)
13
- record.fields('008').filter_map do |field|
13
+ record.fields('008').filter_map { |field|
14
14
  four_digit_year = sanitize_partially_known_date(field.value[7, 4], '0')
15
15
 
16
- next unless four_digit_year.present?
16
+ next if four_digit_year.blank?
17
17
 
18
18
  DateTime.new(four_digit_year.to_i)
19
- end.first
19
+ }.first
20
20
  end
21
21
 
22
22
  # Retrieve date added (subfield 'q') from enriched marc 'itm' field.
@@ -24,7 +24,7 @@ module PennMARC
24
24
  # @param [MARC::Record] record
25
25
  # @return [DateTime, nil] The date added, or nil if date found in record is invalid
26
26
  def added(record)
27
- record.fields(EnrichedMarc::TAG_ITEM).flat_map do |field|
27
+ record.fields(EnrichedMarc::TAG_ITEM).flat_map { |field|
28
28
  field.filter_map do |subfield|
29
29
  # skip unless field has date created subfield
30
30
  next unless subfield_defined?(field, EnrichedMarc::SUB_ITEM_DATE_CREATED)
@@ -42,7 +42,7 @@ module PennMARC
42
42
  puts "Error parsing date in date added subfield: #{subfield.value} - #{e}"
43
43
  nil
44
44
  end
45
- end.max
45
+ }.max
46
46
  end
47
47
 
48
48
  # Retrieve date last updated from {https://www.loc.gov/marc/bibliographic/bd005.html 005 field}.
@@ -51,19 +51,20 @@ module PennMARC
51
51
  # @param [MARC::Record] record
52
52
  # @return [DateTime, nil] The date last updated, or nil if date found in record is invalid
53
53
  def last_updated(record)
54
- record.fields('005').filter_map do |field|
55
- date_time_string = field.value
54
+ record.fields('005').filter_map { |field|
55
+ begin
56
+ date_time_string = field.value
56
57
 
57
- next if date_time_string.blank?
58
+ next if date_time_string.blank?
58
59
 
59
- next if date_time_string.start_with?('0000')
60
+ next if date_time_string.start_with?('0000')
60
61
 
61
- DateTime.iso8601(date_time_string).to_datetime
62
-
63
- rescue ArgumentError => e
64
- puts "Error parsing last updated date: #{date_time_string} - #{e}"
65
- nil
66
- end.first
62
+ DateTime.iso8601(date_time_string).to_datetime
63
+ rescue ArgumentError => e
64
+ puts "Error parsing last updated date: #{date_time_string} - #{e}"
65
+ nil
66
+ end
67
+ }.first
67
68
  end
68
69
 
69
70
  private
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PennMARC
4
- # Do Edition-y stuff
4
+ # Do Edition and edition-related field processing.
5
5
  class Edition < Helper
6
6
  class << self
7
7
  # Edition values for display on a record page. Field 250 is information relating to the edition of a work as
@@ -14,9 +14,9 @@ module PennMARC
14
14
  # @param [MARC::Record] record
15
15
  # @return [Array<String>] array of editions and their alternates
16
16
  def show(record)
17
- record.fields('250').map do |field|
17
+ record.fields('250').map { |field|
18
18
  join_subfields(field, &subfield_not_in?(%w[6 8]))
19
- end + linked_alternate_not_6_or_8(record, '250')
19
+ } + linked_alternate_not_6_or_8(record, '250')
20
20
  end
21
21
 
22
22
  # Edition values for display in search results. Just grab the first 250 field.
@@ -24,7 +24,7 @@ module PennMARC
24
24
  # @return [String, NilClass] string of all first 250 subfields, excluding 6 and 8
25
25
  def values(record)
26
26
  edition = record.fields('250').first
27
- return unless edition.present?
27
+ return if edition.blank?
28
28
 
29
29
  join_subfields(edition, &subfield_not_in?(%w[6 8]))
30
30
  end
@@ -34,18 +34,21 @@ module PennMARC
34
34
  # display.
35
35
  # https://www.loc.gov/marc/bibliographic/bd775.html
36
36
  # @param [MARC::Record] record
37
+ # @param [Hash] relator_mapping
37
38
  # @return [Array<String>] array of other edition strings
38
- def other_show(record, relator_mapping)
39
- record.fields('775').filter_map do |field|
39
+ def other_show(record, relator_mapping = relator_map)
40
+ values = record.fields('775').filter_map do |field|
40
41
  next unless subfield_defined?(field, :i)
41
42
 
42
43
  other_edition_value(field, relator_mapping)
43
- end + record.fields('880').filter_map do |field|
44
+ end
45
+ values += record.fields('880').filter_map do |field|
44
46
  next unless field.indicator2.blank? && subfield_value_in?(field, '6', %w[775]) &&
45
47
  subfield_defined?(field, 'i')
46
48
 
47
49
  other_edition_value(field, relator_mapping)
48
50
  end
51
+ values
49
52
  end
50
53
 
51
54
  private
@@ -56,7 +59,7 @@ module PennMARC
56
59
  # @return [String (frozen)] assembled other version string
57
60
  def other_edition_value(field, relator_mapping)
58
61
  subi = remove_paren_value_from_subfield_i(field) || ''
59
- other_editions = field.filter_map do |sf|
62
+ other_editions = field.filter_map { |sf|
60
63
  next if %w[6 8].member?(sf.code)
61
64
 
62
65
  if %w[s x z].member?(sf.code)
@@ -67,8 +70,8 @@ module PennMARC
67
70
 
68
71
  " #{relator}. "
69
72
  end
70
- end.join
71
- other_editions_append = field.filter_map do |sf|
73
+ }.join
74
+ other_editions_append = field.filter_map { |sf|
72
75
  next if %w[6 8].member?(sf.code)
73
76
 
74
77
  if %w[i h s t x z e f o r w y 7].exclude?(sf.code)
@@ -76,7 +79,7 @@ module PennMARC
76
79
  elsif sf.code == 'h'
77
80
  " (#{sf.value}) "
78
81
  end
79
- end.join
82
+ }.join
80
83
  prepend = trim_trailing(:period, subi).squish
81
84
 
82
85
  if other_editions.present? || other_editions_append.present?
@@ -68,10 +68,10 @@ module PennMARC
68
68
  # for this helper method
69
69
  # @note ported from get_format
70
70
  # @param [MARC::Record] record
71
- # @param [Hash] location_map
71
+ # @param [Hash] location_mapping
72
72
  # @return [Array<String>] format values for faceting
73
73
 
74
- def facet(record, location_map)
74
+ def facet(record, location_mapping = location_map)
75
75
  formats = []
76
76
  format_code = leader_format(record.leader)
77
77
  f007 = record.fields('007').map(&:value)
@@ -88,7 +88,8 @@ module PennMARC
88
88
  end
89
89
 
90
90
  # get all specific_location values from inventory info
91
- locations = Location.location record: record, location_map: location_map, display_value: :specific_location
91
+ locations = Location.location record: record, location_mapping: location_mapping,
92
+ display_value: :specific_location
92
93
 
93
94
  if include_manuscripts?(locations)
94
95
  formats << MANUSCRIPT
@@ -147,6 +148,16 @@ module PennMARC
147
148
  end
148
149
  end
149
150
 
151
+ # Retrieve cartographic reference data for map/atlas formats for display from
152
+ # {https://www.oclc.org/bibformats/en/2xx/255.html 255} and {https://www.oclc.org/bibformats/en/3xx/342.html 342}
153
+ # @param [MARC::Record] record
154
+ # @return [Array<String>]
155
+ def cartographic_show(record)
156
+ record.fields(%w[255 342]).map do |field|
157
+ join_subfields(field, &subfield_not_in?(%w[6 8]))
158
+ end
159
+ end
160
+
150
161
  # Check if a set of locations has any locations that include the term 'manuscripts'
151
162
  # @param [Array<String>] locations
152
163
  # @return [Boolean]
@@ -162,12 +173,12 @@ module PennMARC
162
173
  # @param [MARC::Record] record
163
174
  # @return [Array]
164
175
  def curated_format(record)
165
- record.fields('944').filter_map do |field|
176
+ record.fields('944').filter_map { |field|
166
177
  subfield_a = field.find { |sf| sf.code == 'a' }
167
178
  next if subfield_a.nil? || (subfield_a.value == subfield_a.value.to_i.to_s)
168
179
 
169
180
  subfield_a.value
170
- end.uniq
181
+ }.uniq
171
182
  end
172
183
 
173
184
  # @param [String] format_code
@@ -11,9 +11,9 @@ module PennMARC
11
11
  # @param [MARC::Record] record
12
12
  # @return [Array<String>] array of genre values for search
13
13
  def search(record)
14
- record.fields('655').map do |field|
14
+ record.fields('655').map { |field|
15
15
  join_subfields(field, &subfield_not_in?(%w[0 2 5 c]))
16
- end.uniq
16
+ }.uniq
17
17
  end
18
18
 
19
19
  # Genre values for display. We display Genre/Term values if they fulfill the following criteria:
@@ -29,34 +29,35 @@ module PennMARC
29
29
  # @param [MARC::Record] record
30
30
  # @return [Array<String>] array of genre values for display
31
31
  def show(record)
32
- record.fields(%w[655 880]).filter_map do |field|
32
+ record.fields(%w[655 880]).filter_map { |field|
33
33
  next unless allowed_genre_field?(field)
34
34
 
35
35
  next if field.tag == '880' && subfield_values(field, '6').exclude?('655')
36
36
 
37
- sub_with_hyphens = field.find_all(&subfield_not_in?(%w[0 2 5 6 8 c e w])).map do |sf|
37
+ sub_with_hyphens = field.find_all(&subfield_not_in?(%w[0 2 5 6 8 c e w])).map { |sf|
38
38
  sep = %w[a b].exclude?(sf.code) ? ' -- ' : ' '
39
39
  sep + sf.value
40
- end.join.lstrip
40
+ }.join.lstrip
41
41
  "#{sub_with_hyphens} #{field.find_all(&subfield_in?(%w[e w])).join(' -- ')}".strip
42
- end.uniq
42
+ }.uniq
43
43
  end
44
44
 
45
45
  # Genre values for faceting. We only set Genre facet values for movies (videos) and manuscripts(?)
46
46
  # @todo the Genre facet in Franklin is pretty ugly. It could be cleaned up by limiting the subfields included
47
47
  # here and cleaning up punctuation.
48
48
  # @param [MARC::Record] record
49
- # @param [Hash] location_map
49
+ # @param [Hash] location_mapping
50
50
  # @return [Array<String>]
51
- def facet(record, location_map)
52
- locations = Location.location record: record, location_map: location_map, display_value: :specific_location
51
+ def facet(record, location_mapping = location_map)
52
+ locations = Location.location record: record, location_mapping: location_mapping,
53
+ display_value: :specific_location
53
54
  manuscript = Format.include_manuscripts?(locations)
54
55
  video = record.fields('007').any? { |field| field.value.starts_with? 'v' }
55
56
  return [] unless manuscript || video
56
57
 
57
- record.fields('655').filter_map do |field|
58
+ record.fields('655').filter_map { |field|
58
59
  join_subfields field, &subfield_not_in?(%w[0 2 5 c])
59
- end.uniq
60
+ }.uniq
60
61
  end
61
62
 
62
63
  private