Class: PennMARC::Identifier
- Defined in:
- lib/pennmarc/helpers/identifier.rb
Overview
Parser methods for extracting identifier values.
Constant Summary
Constants included from Util
Util::TRAILING_PUNCTUATIONS_PATTERNS
Class Method Summary collapse
-
.doi_show(record) ⇒ Array<String>
Retrieve DOI values stored in 024.
-
.fingerprint_show(record) ⇒ Array<String>
Retrieve fingerprint for display from the 026 field.
-
.host_record_id(record) ⇒ Array<String>
Gets any Host record MMS ID values from an Enriched::Pub::RELATED_RECORD_TAG field added during Alma enrichment.
- .isbn_show(record) ⇒ Array<String>
- .issn_show(record) ⇒ Array<String>
-
.isxn_search(record) ⇒ Array<String>
Get normalized ISXN values for searching of a record.
-
.mmsid(record) ⇒ String
Get Alma MMS ID value.
-
.oclc_id_search(record) ⇒ Array<String>
Retrieve valid and invalid numeric OCLC IDs from 035 field for search.
-
.oclc_id_show(record) ⇒ String?
Get numeric OCLC ID of first 035 field with an OCLC ID defined in subfield ‘a’.
-
.publisher_number_search(record) ⇒ Array<String>
Get publisher issued identifiers for searching of a record.
- .publisher_number_show(record) ⇒ Array<string>
Methods included from Util
#append_relator, #append_trailing, #datafield_and_linked_alternate, #field_defined?, #field_or_its_linked_alternate?, #join_and_squish, #join_subfields, #linked_alternate, #linked_alternate_not_6_or_8, #no_subfield_value_matches?, #prefixed_subject_and_alternate, #relator, #relator_join_separator, #relator_term_subfield, #remove_paren_value_from_subfield_i, #subfield_defined?, #subfield_in?, #subfield_not_in?, #subfield_undefined?, #subfield_value?, #subfield_value_in?, #subfield_value_not_in?, #subfield_values, #subfield_values_for, #substring_after, #substring_before, #translate_relator, #trim_punctuation, #trim_trailing, #trim_trailing!, #valid_subject_genre_source_code?
Class Method Details
.doi_show(record) ⇒ Array<String>
Retrieve DOI values stored in 024. Penn MARC records give the first indicator a value of ‘7’ and ǂ2 a value of ‘doi’ to denote that ǂa is a doi.
151 152 153 154 155 156 157 158 159 160 |
# File 'lib/pennmarc/helpers/identifier.rb', line 151 def doi_show(record) record.fields('024').filter_map { |field| # skip unless indicator1 is '7' next unless field.indicator1.in?(%w[7]) # skip unless ǂ2 is the string literal 'doi' next unless subfield_value_in?(field, '2', %w[doi]) join_subfields(field, &subfield_in?(%w[a])) }.uniq end |
.fingerprint_show(record) ⇒ Array<String>
Retrieve fingerprint for display from the 026 field
141 142 143 144 145 |
# File 'lib/pennmarc/helpers/identifier.rb', line 141 def fingerprint_show(record) record.fields('026').map { |field| join_subfields(field, &subfield_not_in?(%w[2 5 6 8])) }.uniq end |
.host_record_id(record) ⇒ Array<String>
Gets any Host record MMS ID values from an Enriched::Pub::RELATED_RECORD_TAG field added during Alma enrichment. This aids in our handling of “bound with” records.
166 167 168 169 170 171 172 |
# File 'lib/pennmarc/helpers/identifier.rb', line 166 def host_record_id(record) record.fields(Enriched::Pub::RELATED_RECORD_TAGS).filter_map { |field| next unless subfield_value?(field, 'c', /contains/i) subfield_values field, :w }.flatten.uniq end |
.isbn_show(record) ⇒ Array<String>
36 37 38 39 40 41 42 43 |
# File 'lib/pennmarc/helpers/identifier.rb', line 36 def isbn_show(record) values = record.fields('020').filter_map do |field| joined_isbn = join_subfields(field, &subfield_in?(%w[a])) joined_isbn.presence end isbn_values = values + linked_alternate(record, '020', &subfield_in?(%w[a])) isbn_values.uniq end |
.issn_show(record) ⇒ Array<String>
50 51 52 53 54 55 56 57 |
# File 'lib/pennmarc/helpers/identifier.rb', line 50 def issn_show(record) values = record.fields('022').filter_map do |field| joined_issn = join_subfields(field, &subfield_in?(%w[a])) joined_issn.presence end issn_values = values + linked_alternate(record, '022', &subfield_in?(%w[a])) issn_values.uniq end |
.isxn_search(record) ⇒ Array<String>
21 22 23 24 25 26 27 28 29 |
# File 'lib/pennmarc/helpers/identifier.rb', line 21 def isxn_search(record) record.fields(%w[020 022]).filter_map { |field| if field.tag == '020' field.filter_map { |subfield| normalize_isbn(subfield.value) if subfield_in?(%w[a z]).call(subfield) } else field.filter_map { |subfield| subfield.value if subfield_in?(%w[a l m y z]).call(subfield) } end }.flatten.uniq end |
.mmsid(record) ⇒ String
Get Alma MMS ID value
11 12 13 |
# File 'lib/pennmarc/helpers/identifier.rb', line 11 def mmsid(record) record.fields('001').first.value end |
.oclc_id_search(record) ⇒ Array<String>
Retrieve valid and invalid numeric OCLC IDs from 035 field for search.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/pennmarc/helpers/identifier.rb', line 86 def oclc_id_search(record) record.fields('035').flat_map { |field| field.filter_map do |subfield| # skip unless subfield 'a' or 'z' next unless subfield.code.in?(%w[a z]) # skip unless subfield value matches OCLC ID next unless subfield_is_oclc?(subfield) # search for numeric part of oclc id match = match_oclc_number(subfield) # skip unless search to find numeric part of oclc id has a match next unless match match[1] end }.uniq end |
.oclc_id_show(record) ⇒ String?
Get numeric OCLC ID of first 035 field with an OCLC ID defined in subfield ‘a’.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/pennmarc/helpers/identifier.rb', line 63 def oclc_id_show(record) ids = Array.wrap(record.fields('035') .find { |field| field.any? { |subfield| subfield_a_is_oclc?(subfield) } }) ids.flat_map { |field| field.filter_map do |subfield| # skip unless subfield 'a' is an oclc id value next unless subfield_a_is_oclc?(subfield) # search for numeric part of oclc id (e.g. '610094484' in '(OCoLC)ocn610094484') match = match_oclc_number(subfield) # skip unless search to find numeric part of oclc id has a match next unless match match[1] end }.first end |
.publisher_number_search(record) ⇒ Array<String>
131 132 133 134 135 136 |
# File 'lib/pennmarc/helpers/identifier.rb', line 131 def publisher_number_search(record) record.fields(%w[024 028]).filter_map { |field| joined_identifiers = join_subfields(field, &subfield_in?(%w[a])) joined_identifiers.presence }.uniq end |
.publisher_number_show(record) ⇒ Array<string>
113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/pennmarc/helpers/identifier.rb', line 113 def publisher_number_show(record) record.fields(%w[024 028 880]).filter_map { |field| next if field.tag == '880' && no_subfield_value_matches?(field, '6', /^(024|028)/) # do not return doi values from 024 ǂ2 if field.tag == '024' && subfield_value_in?(field, '2', %w[doi]) join_subfields(field, &subfield_not_in?(%w[a 2 5 6])).presence else join_subfields(field, &subfield_not_in?(%w[5 6])).presence end }.uniq end |