Class: PennMARC::Database
- Defined in:
- lib/pennmarc/helpers/database.rb
Overview
Parses Database Subject Category and Database Type local fields
Constant Summary collapse
- DATABASES_FACET_VALUE =
Database format type used to facet databases, found in local field 944 subfield ‘a’.
'Database & Article Index'
- COI_CODE =
Penn Libraries’ Community of Interest code used in local field 943 subfield ‘2’.
'penncoi'
Constants included from Util
Util::TRAILING_PUNCTUATIONS_PATTERNS
Class Method Summary collapse
-
.category_facet(record) ⇒ Array<String>
Retrieves database subject category/communities of interest (subfield ‘a’) from local field 943.
-
.subcategory_facet(record) ⇒ Array<String>
Concatenates database subject category with database sub subject category in the format “category–subcategory” if both values are present.
-
.type_facet(record) ⇒ Array<String>
Retrieves database subtype (subfield ‘b’) from local field 944.
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
.category_facet(record) ⇒ Array<String>
Retrieves database subject category/communities of interest (subfield ‘a’) from local field 943. Only returns database subject category if Penn’s Community of Interest code is present in subfield ‘2’.
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/pennmarc/helpers/database.rb', line 37 def category_facet(record) return [] unless curated_db?(record) record.fields('943').filter_map { |field| # skip unless Community of Interest code is in subfield '2' next unless subfield_value?(field, '2', /#{COI_CODE}/o) category = field.find { |subfield| subfield.code == 'a' } category&.value }.uniq end |
.subcategory_facet(record) ⇒ Array<String>
return value differs from legacy implementation. This version only returns [“category–subcategory”] or an empty array.
Concatenates database subject category with database sub subject category in the format “category–subcategory” if both values are present. Retrieves both values respectively from subfield ‘a’ and subfield ‘b’ of local field 943. Only returns subcategory if Penn’s Community of Interest code is present in subfield ‘2’.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/pennmarc/helpers/database.rb', line 58 def subcategory_facet(record) return [] unless curated_db?(record) record.fields('943').filter_map { |field| # skip unless Community of Interest code is in subfield '2' next unless subfield_value?(field, '2', /#{COI_CODE}/o) category = field.find { |subfield| subfield.code == 'a' } # skip if category is blank next if category.blank? subcategory = field.find { |subfield| subfield.code == 'b' } # skip if subcategory is blank next if subcategory.blank? "#{category.value}--#{subcategory.value}" }.uniq end |
.type_facet(record) ⇒ Array<String>
Retrieves database subtype (subfield ‘b’) from local field 944. Only returns database subtype if Penn’s Database facet value is present in subfield ‘a’.
21 22 23 24 25 26 27 28 29 |
# File 'lib/pennmarc/helpers/database.rb', line 21 def type_facet(record) record.fields('944').filter_map { |field| # skip unless specified database format type present next unless subfield_value?(field, 'a', /#{DATABASES_FACET_VALUE}/o) type = field.find { |subfield| subfield.code == 'b' } type&.value }.uniq end |