Class: PennMARC::Format
Overview
Handle parsing out “Format” and “Other Format” values. Special care goes into controlling the format values for faceting.
Constant Summary collapse
- ARCHIVE =
These constants represent the set of desired Format values for faceting.
'Archive'
- BOOK =
'Book'
- CONFERENCE_EVENT =
'Conference/Event'
- DATAFILE =
'Datafile'
- GOVDOC =
'Government document'
- IMAGE =
'Image'
- JOURNAL_PERIODICAL =
'Journal/Periodical'
- MANUSCRIPT =
'Manuscript'
- MAP_ATLAS =
'Map/Atlas'
- MICROFORMAT =
'Microformat'
- MUSICAL_SCORE =
'Musical score'
- NEWSPAPER =
'Newspaper'
- OTHER =
'Other'
- PROJECTED_GRAPHIC =
'Projected graphic'
- SOUND_RECORDING =
'Sound recording'
- THESIS_DISSERTATION =
'Thesis/Dissertation'
- THREE_D_OBJECT =
'3D object'
- VIDEO =
'Video'
- WEBSITE_DATABASE =
'Website/Database'
- ARCHIVE_LOCATIONS =
Values encoded in MARC that we use to determine “Archive” format
%w[archarch musearch scfreed univarch archivcoll].freeze
Constants included from Util
Util::TRAILING_PUNCTUATIONS_PATTERNS
Class Method Summary collapse
- .cartographic_show(record) ⇒ Array<String>
-
.facet(record) ⇒ Array<String>
Get Format values for faceting.
-
.include_manuscripts?(format_code) ⇒ Boolean
Check if leader format code is either ‘t’, ‘f’, or ‘d’.
-
.other_show(record) ⇒ Array<String>
Show “Other Format” values from 776 and any 880 linkage.
- .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
.cartographic_show(record) ⇒ Array<String>
131 132 133 134 135 |
# File 'lib/pennmarc/helpers/format.rb', line 131 def cartographic_show(record) record.fields(%w[255 342]).map { |field| join_subfields(field, &subfield_not_in?(%w[6 8])) }.uniq end |
.facet(record) ⇒ Array<String>
ported from get_format
Get Format values for faceting. Format values are determined using complex logic for each possible format value. The primary fields considered in determining Format facet values are:
-
“Type of Record” and “Bibliographic level” values extracted from the MARC leader.
-
Location name values and “Classification part” from Alma “enhanced” MARC holding/item information
-
007 values, the first 008 value, and the first character form all 006 values (form)
-
Medium values from 245 ǂh
-
Media Type values from 337 ǂa
Additional fields are considered for many of the formats. Much of this logic has been moved to private methods to keep this method from becoming too unwieldy.
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/pennmarc/helpers/format.rb', line 76 def facet(record) formats = [] format_code = leader_format(record.leader) f007 = record.fields('007').map(&:value) f008 = record.fields('008').first&.value || '' f006_forms = record.fields('006').map { |field| field.value[0] } title_medium = subfield_values_for tag: '245', subfield: :h, record: record media_type = subfield_values_for tag: '337', subfield: :a, record: record # any of these formats << MANUSCRIPT if include_manuscripts?(format_code) formats << ARCHIVE if archive?(record) formats << MICROFORMAT if micro_or_microform?(call_nums(record), f007, f008, media_type, title_medium) formats << THESIS_DISSERTATION if thesis_or_dissertation?(format_code, record) formats << CONFERENCE_EVENT if conference_event?(record) formats << NEWSPAPER if newspaper?(f008, format_code) formats << GOVDOC if government_document?(f008, record, format_code) formats << WEBSITE_DATABASE if website_database?(f006_forms, format_code) formats << BOOK if book?(format_code, media_type, record) formats << MUSICAL_SCORE if musical_score?(format_code) formats << MAP_ATLAS if map_atlas?(format_code) formats << graphical_media_type(f007) if graphical_media?(format_code) formats << SOUND_RECORDING if sound_recording?(format_code) formats << IMAGE if image?(format_code) formats << DATAFILE if datafile?(format_code) formats << JOURNAL_PERIODICAL if journal_periodical?(format_code) formats << THREE_D_OBJECT if three_d_object?(format_code) formats.concat(curated_format(record)) formats << OTHER if formats.empty? formats.uniq end |
.include_manuscripts?(format_code) ⇒ Boolean
Check if leader format code is either ‘t’, ‘f’, or ‘d’
140 141 142 |
# File 'lib/pennmarc/helpers/format.rb', line 140 def include_manuscripts?(format_code) format_code.first.in? %w[t f d] end |
.other_show(record) ⇒ Array<String>
is 774 an error in the linked field in legacy? i changed to 776 here
Show “Other Format” values from 776 and any 880 linkage.
114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/pennmarc/helpers/format.rb', line 114 def other_show(record) values = record.fields('776').filter_map do |field| value = join_subfields(field, &subfield_in?(%w[i a s t o])) next if value.blank? value end other_formats = values + linked_alternate(record, '776') do |sf| sf.code.in? %w[i a s t o] end other_formats.uniq end |
.show(record) ⇒ Array<String>
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/pennmarc/helpers/format.rb', line 38 def show(record) results = record.fields('300').map { |f| join_subfields(f, &subfield_not_in?(%w[3 6 8])) } results += record.fields(%w[254 255 310 342 352 362]).map do |f| join_subfields(f, &subfield_not_in?(%w[6 8])) end results += record.fields('340').map { |f| join_subfields(f, &subfield_not_in?(%w[0 2 6 8])) } results += record.fields('880').map do |f| # skip any 880s associated with non format fields next unless subfield_value?(f, '6', /^(254|255|300|310|340|342|352|362)/) subfield_to_ignore = if subfield_value?(f, 6, /^300/) %w[3 6 8] elsif subfield_value?(f, 6, /^340/) %w[0 2 6 8] else %w[6 8] end join_subfields(f, &subfield_not_in?(subfield_to_ignore)) end results.compact_blank.uniq end |