Module: CocinaDisplay::Concerns::Forms

Included in:
CocinaDisplay::CocinaRecord, RelatedResource
Defined in:
lib/cocina_display/concerns/forms.rb

Overview

Methods for extracting format/genre information from a Cocina object

Instance Method Summary collapse

Instance Method Details

#all_formsArray<Form>

Collapses all nested form values into an array of Form objects. Preserves resource type without flattening, since it can be structured.

Returns:

  • (Array<Form>)


111
112
113
114
115
# File 'lib/cocina_display/concerns/forms.rb', line 111

def all_forms
  @all_forms ||= path("$.description.form.*")
    .flat_map { |form| Utils.flatten_nested_values(form, atomic_types: ["resource type"]) }
    .map { |form| CocinaDisplay::Forms::Form.from_cocina(form) }
end

#all_resource_typesArray<ResourceType>

All resource types forms, as ResourceTypes.

Returns:

  • (Array<ResourceType>)


150
151
152
# File 'lib/cocina_display/concerns/forms.rb', line 150

def all_resource_types
  all_forms.filter { |form| form.is_a?(CocinaDisplay::Forms::ResourceType) }
end

#archived_website?Boolean

Is the object a web archive?

Returns:

  • (Boolean)


98
99
100
# File 'lib/cocina_display/concerns/forms.rb', line 98

def archived_website?
  genres.include?("Archived website")
end

#cartographic?Boolean

Is the object a cartographic resource?

Returns:

  • (Boolean)


92
93
94
# File 'lib/cocina_display/concerns/forms.rb', line 92

def cartographic?
  resource_type_values.include?("cartographic")
end

#dataset?Boolean

Is the object a dataset?

Returns:

  • (Boolean)


104
105
106
# File 'lib/cocina_display/concerns/forms.rb', line 104

def dataset?
  genres.include?("Dataset")
end

#extent_formsArray<Form>

Form objects with type “extent”.

Returns:

  • (Array<Form>)


131
132
133
# File 'lib/cocina_display/concerns/forms.rb', line 131

def extent_forms
  all_forms.filter { |form| form.type == "extent" }
end

#extentsArray<String>

Extent of the object, such as “1 audiotape” or “1 map”.

Examples:

Oral history interview (sw705fr7011)

record.extents #=> ["1 audiotape", "1 transcript"]

Returns:

  • (Array<String>)


33
34
35
# File 'lib/cocina_display/concerns/forms.rb', line 33

def extents
  extent_forms.map(&:to_s).compact_blank.uniq
end

#form_display_dataArray<DisplayData>

All form-related data to be rendered for display. Includes form, extent, resource type, etc. (but not self-deposit resource types).

Returns:



59
60
61
# File 'lib/cocina_display/concerns/forms.rb', line 59

def form_display_data
  CocinaDisplay::DisplayData.from_objects(all_forms - genre_forms - map_forms - media_forms - self_deposit_resource_types)
end

#form_formsArray<Form>

Form objects with type “form”.

Returns:

  • (Array<Form>)


119
120
121
# File 'lib/cocina_display/concerns/forms.rb', line 119

def form_forms
  all_forms.filter { |form| form.type == "form" }
end

#form_note_display_dataArray<DisplayData>

All form notes to be rendered for display.

Returns:



79
80
81
82
# File 'lib/cocina_display/concerns/forms.rb', line 79

def form_note_display_data
  CocinaDisplay::DisplayData.from_cocina(path("$.description.form[*].note[*]"),
    label: I18n.t("cocina_display.field_label.form.note"))
end

#formsArray<String>

Physical or digital forms of the object.

Examples:

GIS dataset (nz187ct8959)

record.forms #=> ["map", "optical disc", "electronic resource"]

Returns:

  • (Array<String>)


25
26
27
# File 'lib/cocina_display/concerns/forms.rb', line 25

def forms
  form_forms.map(&:to_s).compact_blank.uniq
end

#frequencyArray<String>

Frequency terms for a periodical, drawn from the event notes.

Returns:

  • (Array<String>)


174
175
176
# File 'lib/cocina_display/concerns/forms.rb', line 174

def frequency
  events.flat_map(&:notes).filter { |note| note.type == "frequency" }.map { |note| note.to_s.downcase }.uniq
end

#genre_display_dataArray<DisplayData>

All genre-related data to be rendered for display. Includes both form genres, subject genres, and self-deposit resource types.

Returns:



66
67
68
# File 'lib/cocina_display/concerns/forms.rb', line 66

def genre_display_data
  CocinaDisplay::DisplayData.from_objects(genre_forms + genre_subjects + self_deposit_resource_types)
end

#genre_formsArray<Form>

Form objects with type “genre”.

Returns:

  • (Array<Form>)


125
126
127
# File 'lib/cocina_display/concerns/forms.rb', line 125

def genre_forms
  all_forms.filter { |form| form.type == "genre" }
end

#genresArray<String>

Genres of the object, capitalized for display.

Examples:

GIS dataset (nz187ct8959)

record.genres #=> ["Cartographic dataset", "Geospatial data", "Geographic information systems data"]

Returns:

  • (Array<String>)


41
42
43
# File 'lib/cocina_display/concerns/forms.rb', line 41

def genres
  genre_forms.map(&:to_s).compact_blank.uniq
end

#genres_searchArray<String>

Note:

These values are added for discovery in SearchWorks but not for display.

Genres of the object, with additional values added for search/faceting.

Returns:

  • (Array<String>)


48
49
50
51
52
53
54
# File 'lib/cocina_display/concerns/forms.rb', line 48

def genres_search
  genres.tap do |values|
    values << "Thesis/Dissertation" if values.include?("Thesis")
    values << "Conference proceedings" if values.include?("Conference publication")
    values << "Government document" if values.include?("Government publication")
  end.uniq
end

#issuance_termsArray<String>

Issuance terms for a work, drawn from the event notes.

Returns:

  • (Array<String>)


168
169
170
# File 'lib/cocina_display/concerns/forms.rb', line 168

def issuance_terms
  events.flat_map(&:notes).filter { |note| note.type == "issuance" }.map { |note| note.to_s.downcase }.uniq
end

#map_display_dataArray<DisplayData>

All map-related data to be rendered for display. Includes map scale, projection info, and geographic coordinate subjects.

Returns:



73
74
75
# File 'lib/cocina_display/concerns/forms.rb', line 73

def map_display_data
  CocinaDisplay::DisplayData.from_objects(map_forms + coordinate_subjects)
end

#map_formsArray<Form>

Form objects with types related to map data.

Returns:

  • (Array<Form>)


137
138
139
# File 'lib/cocina_display/concerns/forms.rb', line 137

def map_forms
  all_forms.filter { |form| ["map scale", "map projection"].include?(form.type) }
end

#media_formsArray<Form>

Note:

These are excluded from the general form display data.

Form objects with types that are media-related.

Returns:

  • (Array<Form>)


144
145
146
# File 'lib/cocina_display/concerns/forms.rb', line 144

def media_forms
  all_forms.filter { |form| ["reformatting quality", "media type"].include?(form.type) }
end

#mods_resource_typesArray<String>

Resource types of the object, expressed in SearchWorks controlled vocabulary.

Returns:

  • (Array<String>)


17
18
19
# File 'lib/cocina_display/concerns/forms.rb', line 17

def mods_resource_types
  all_resource_types.select { |type| type.mods? }.map(&:to_s)
end

#periodical?Boolean

Is the object a periodical or serial?

Returns:

  • (Boolean)


86
87
88
# File 'lib/cocina_display/concerns/forms.rb', line 86

def periodical?
  issuance_terms.include?("periodical") || issuance_terms.include?("serial") || frequency.any?
end

#resource_type_valuesArray<String>

Display values of all resource types.

Returns:

  • (Array<String>)


162
163
164
# File 'lib/cocina_display/concerns/forms.rb', line 162

def resource_type_values
  all_resource_types.map(&:to_s).uniq
end

#searchworks_resource_typesArray<String>

Resource types of the object, expressed in SearchWorks controlled vocabulary.

Returns:

  • (Array<String>)


9
10
11
12
13
# File 'lib/cocina_display/concerns/forms.rb', line 9

def searchworks_resource_types
  mapped_values = resource_type_values.flat_map { |resource_type| searchworks_resource_type(resource_type) }
  mapped_values << "Dataset" if dataset?
  mapped_values.uniq
end

#self_deposit_resource_typesArray<ResourceType>

ResourceType objects that are Stanford self-deposit resource types.

Returns:

  • (Array<ResourceType>)


156
157
158
# File 'lib/cocina_display/concerns/forms.rb', line 156

def self_deposit_resource_types
  all_resource_types.filter { |resource_type| resource_type.stanford_self_deposit? }
end