Class: PennMARC::Format

Inherits:
Helper
  • Object
show all
Defined in:
lib/pennmarc/helpers/format.rb

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'

Class Method Summary collapse

Methods included from Util

#datafield_and_linked_alternate, #join_and_squish, #join_subfields, #linked_alternate, #linked_alternate_not_6_or_8, #prefixed_subject_and_alternate, #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_trailing, #valid_subject_genre_source_code?

Class Method Details

.cartographic_show(record) ⇒ Array<String>

Retrieve cartographic reference data for map/atlas formats for display from 255 and 342

Parameters:

  • record (MARC::Record)

Returns:

  • (Array<String>)


155
156
157
158
159
# File 'lib/pennmarc/helpers/format.rb', line 155

def cartographic_show(record)
  record.fields(%w[255 342]).map do |field|
    join_subfields(field, &subfield_not_in?(%w[6 8]))
  end
end

.facet(record, location_map: Mappers.location) ⇒ Array<String>

TODO:

is the conditional structure here still best practice? see the “Thesis on Microfilm” case in the specs for this helper method

Note:

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:

  1. “Type of Record” and “Bibliographic level” values extracted from the MARC leader.

  2. Location name values and “Classification part” from Alma “enhanced” MARC holding/item information

  3. 007 values, the first 008 value, and the first character form all 006 values (form)

  4. Medium values from 245 ǂh

  5. 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.

Parameters:

  • record (MARC::Record)
  • location_map (Hash) (defaults to: Mappers.location)

Returns:

  • (Array<String>)

    format values for faceting



74
75
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/pennmarc/helpers/format.rb', line 74

def facet(record, location_map: Mappers.location)
  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

  # Get Call Number for holdings - ǂh gives us the 'Classification part' which can contain strings like
  # 'Microfilm'
  call_nums = record.fields(EnrichedMarc::TAG_HOLDING).map do |field|
    join_subfields(field, &subfield_in?([EnrichedMarc::SUB_HOLDING_CLASSIFICATION_PART,
                                         EnrichedMarc::SUB_HOLDING_ITEM_PART]))
  end

  # get all specific_location values from inventory info
  locations = Location.location record: record, location_map: location_map,
                                display_value: :specific_location

  if include_manuscripts?(locations)
    formats << MANUSCRIPT
  elsif archives_but_not_cajs_or_nursing?(locations)
    formats << ARCHIVE
  elsif micro_or_microform?(call_nums, locations, media_type, title_medium)
    formats << MICROFORMAT
  else
    # any of these
    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)

    # but only one of these
    formats << if website_database?(f006_forms, format_code)
                 WEBSITE_DATABASE
               elsif book?(format_code, title_medium, record)
                 BOOK
               elsif musical_score?(format_code)
                 MUSICAL_SCORE
               elsif map_atlas?(format_code)
                 MAP_ATLAS
               elsif graphical_media?(format_code)
                 graphical_media_type(f007)
               elsif sound_recording?(format_code)
                 SOUND_RECORDING
               elsif image?(format_code)
                 IMAGE
               elsif datafile?(format_code)
                 DATAFILE
               elsif journal_periodical?(format_code)
                 JOURNAL_PERIODICAL
               elsif three_d_object?(format_code)
                 THREE_D_OBJECT
               else
                 OTHER
               end
  end
  formats.concat(curated_format(record))
end

.include_manuscripts?(locations) ⇒ Boolean

Check if a set of locations has any locations that include the term ‘manuscripts’

Parameters:

  • locations (Array<String>)

Returns:

  • (Boolean)


164
165
166
# File 'lib/pennmarc/helpers/format.rb', line 164

def include_manuscripts?(locations)
  locations.any? { |loc| loc =~ /manuscripts/i }
end

.other_show(record) ⇒ Array

TODO:

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.

Parameters:

  • record (MARC::Record)

Returns:

  • (Array)

    other format values for display



139
140
141
142
143
144
145
146
147
148
149
# File 'lib/pennmarc/helpers/format.rb', line 139

def other_show(record)
  other_formats = 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 + linked_alternate(record, '776') do |sf|
    sf.code.in? %w[i a s t o]
  end
end

.show(record) ⇒ Array<String>

Note:

ported from get_format_display

Get any Format values from 300, 254, 255, 310, 342, 352 or 340 field. based on the source field, different subfields are used.

Parameters:

  • record (MARC::Record)

Returns:

  • (Array<String>)

    format values for display



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/pennmarc/helpers/format.rb', line 35

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|
    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
end