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
-
#all_forms ⇒ Array<Form>
Collapses all nested form values into an array of Form objects.
-
#all_resource_types ⇒ Array<ResourceType>
All resource types forms, as ResourceTypes.
-
#archived_website? ⇒ Boolean
Is the object a web archive?.
-
#cartographic? ⇒ Boolean
Is the object a cartographic resource?.
-
#dataset? ⇒ Boolean
Is the object a dataset?.
-
#extent_forms ⇒ Array<Form>
Form objects with type “extent”.
-
#extents ⇒ Array<String>
Extent of the object, such as “1 audiotape” or “1 map”.
-
#form_display_data ⇒ Array<DisplayData>
All form-related data to be rendered for display.
-
#form_forms ⇒ Array<Form>
Form objects with type “form”.
-
#form_note_display_data ⇒ Array<DisplayData>
All form notes to be rendered for display.
-
#forms ⇒ Array<String>
Physical or digital forms of the object.
-
#frequency ⇒ Array<String>
Frequency terms for a periodical, drawn from the event notes.
-
#genre_display_data ⇒ Array<DisplayData>
All genre-related data to be rendered for display.
-
#genre_forms ⇒ Array<Form>
Form objects with type “genre”.
-
#genres ⇒ Array<String>
Genres of the object, capitalized for display.
-
#genres_search ⇒ Array<String>
Genres of the object, with additional values added for search/faceting.
-
#issuance_terms ⇒ Array<String>
Issuance terms for a work, drawn from the event notes.
-
#map_display_data ⇒ Array<DisplayData>
All map-related data to be rendered for display.
-
#map_forms ⇒ Array<Form>
Form objects with types related to map data.
-
#media_forms ⇒ Array<Form>
Form objects with types that are media-related.
-
#mods_resource_types ⇒ Array<String>
Resource types of the object, expressed in SearchWorks controlled vocabulary.
-
#periodical? ⇒ Boolean
Is the object a periodical or serial?.
-
#resource_type_values ⇒ Array<String>
Display values of all resource types.
-
#searchworks_resource_types ⇒ Array<String>
Resource types of the object, expressed in SearchWorks controlled vocabulary.
-
#self_deposit_resource_types ⇒ Array<ResourceType>
ResourceType objects that are Stanford self-deposit resource types.
Instance Method Details
#all_forms ⇒ Array<Form>
Collapses all nested form values into an array of Form objects. Checks both description.form and description.geographic.form. Preserves resource type without flattening, since it can be structured.
119 120 121 122 123 124 125 126 |
# File 'lib/cocina_display/concerns/forms.rb', line 119 def all_forms @all_forms ||= Enumerator::Chain.new( path("$.description.form.*"), path("$.description.geographic.*.form.*") ) .flat_map { |form| Utils.flatten_nested_values(form, atomic_types: ["resource type"]) } .map { |form| CocinaDisplay::Forms::Form.from_cocina(form) } end |
#all_resource_types ⇒ Array<ResourceType>
All resource types forms, as ResourceTypes.
161 162 163 |
# File 'lib/cocina_display/concerns/forms.rb', line 161 def all_resource_types all_forms.filter { |form| form.is_a?(CocinaDisplay::Forms::ResourceType) } end |
#archived_website? ⇒ Boolean
Is the object a web archive?
105 106 107 |
# File 'lib/cocina_display/concerns/forms.rb', line 105 def archived_website? genres.include?("Archived website") end |
#cartographic? ⇒ Boolean
Is the object a cartographic resource?
99 100 101 |
# File 'lib/cocina_display/concerns/forms.rb', line 99 def cartographic? resource_type_values.include?("cartographic") end |
#dataset? ⇒ Boolean
Is the object a dataset?
111 112 113 |
# File 'lib/cocina_display/concerns/forms.rb', line 111 def dataset? genres.include?("Dataset") end |
#extent_forms ⇒ Array<Form>
Form objects with type “extent”.
142 143 144 |
# File 'lib/cocina_display/concerns/forms.rb', line 142 def extent_forms all_forms.filter { |form| form.type == "extent" } end |
#extents ⇒ Array<String>
Extent of the object, such as “1 audiotape” or “1 map”.
34 35 36 |
# File 'lib/cocina_display/concerns/forms.rb', line 34 def extents extent_forms.map(&:to_s).compact_blank.uniq end |
#form_display_data ⇒ Array<DisplayData>
All form-related data to be rendered for display. Includes form, extent, resource type, etc. (but not self-deposit resource types).
60 61 62 |
# File 'lib/cocina_display/concerns/forms.rb', line 60 def form_display_data CocinaDisplay::DisplayData.from_objects(all_forms - genre_forms - map_forms - media_forms - self_deposit_resource_types) end |
#form_forms ⇒ Array<Form>
Form objects with type “form”.
130 131 132 |
# File 'lib/cocina_display/concerns/forms.rb', line 130 def form_forms all_forms.filter { |form| form.type == "form" } end |
#form_note_display_data ⇒ Array<DisplayData>
All form notes to be rendered for display. Checks both description.form.note and description.geographic.form.note.
81 82 83 84 85 86 87 88 89 |
# File 'lib/cocina_display/concerns/forms.rb', line 81 def form_note_display_data CocinaDisplay::DisplayData.from_cocina( Enumerator::Chain.new( path("$.description.form.*.note.*"), path("$.description.geographic.*.form.*.note.*") ), label: I18n.t("cocina_display.field_label.form.note") ) end |
#forms ⇒ Array<String>
Physical or digital forms of the object.
26 27 28 |
# File 'lib/cocina_display/concerns/forms.rb', line 26 def forms form_forms.map(&:to_s).compact_blank.uniq end |
#frequency ⇒ Array<String>
Frequency terms for a periodical, drawn from the event notes.
185 186 187 |
# File 'lib/cocina_display/concerns/forms.rb', line 185 def frequency events.flat_map(&:notes).filter { |note| note.type == "frequency" }.map { |note| note.to_s.downcase }.uniq end |
#genre_display_data ⇒ Array<DisplayData>
All genre-related data to be rendered for display. Includes both form genres, subject genres, and self-deposit resource types.
67 68 69 |
# File 'lib/cocina_display/concerns/forms.rb', line 67 def genre_display_data CocinaDisplay::DisplayData.from_objects(genre_forms + genre_subjects + self_deposit_resource_types) end |
#genre_forms ⇒ Array<Form>
Form objects with type “genre”.
136 137 138 |
# File 'lib/cocina_display/concerns/forms.rb', line 136 def genre_forms all_forms.filter { |form| form.type == "genre" } end |
#genres ⇒ Array<String>
Genres of the object, capitalized for display.
42 43 44 |
# File 'lib/cocina_display/concerns/forms.rb', line 42 def genres genre_forms.map(&:to_s).compact_blank.uniq end |
#genres_search ⇒ Array<String>
These values are added for discovery in SearchWorks but not for display.
Genres of the object, with additional values added for search/faceting.
49 50 51 52 53 54 55 |
# File 'lib/cocina_display/concerns/forms.rb', line 49 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_terms ⇒ Array<String>
Issuance terms for a work, drawn from the event notes.
179 180 181 |
# File 'lib/cocina_display/concerns/forms.rb', line 179 def issuance_terms events.flat_map(&:notes).filter { |note| note.type == "issuance" }.map { |note| note.to_s.downcase }.uniq end |
#map_display_data ⇒ Array<DisplayData>
All map-related data to be rendered for display. Includes map scale, projection info, and geographic coordinate subjects.
74 75 76 |
# File 'lib/cocina_display/concerns/forms.rb', line 74 def map_display_data CocinaDisplay::DisplayData.from_objects(map_forms + coordinate_subjects) end |
#map_forms ⇒ Array<Form>
Form objects with types related to map data.
148 149 150 |
# File 'lib/cocina_display/concerns/forms.rb', line 148 def map_forms all_forms.filter { |form| ["map scale", "map projection"].include?(form.type) } end |
#media_forms ⇒ Array<Form>
These are excluded from the general form display data.
Form objects with types that are media-related.
155 156 157 |
# File 'lib/cocina_display/concerns/forms.rb', line 155 def media_forms all_forms.filter { |form| ["reformatting quality", "media type"].include?(form.type) } end |
#mods_resource_types ⇒ Array<String>
Resource types of the object, expressed in SearchWorks controlled vocabulary.
18 19 20 |
# File 'lib/cocina_display/concerns/forms.rb', line 18 def mods_resource_types all_resource_types.select { |type| type.mods? }.map(&:to_s) end |
#periodical? ⇒ Boolean
Is the object a periodical or serial?
93 94 95 |
# File 'lib/cocina_display/concerns/forms.rb', line 93 def periodical? issuance_terms.include?("periodical") || issuance_terms.include?("serial") || frequency.any? end |
#resource_type_values ⇒ Array<String>
Display values of all resource types.
173 174 175 |
# File 'lib/cocina_display/concerns/forms.rb', line 173 def resource_type_values all_resource_types.map(&:to_s).uniq end |
#searchworks_resource_types ⇒ Array<String>
Resource types of the object, expressed in SearchWorks controlled vocabulary.
9 10 11 12 13 14 |
# 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 << "Software/Multimedia" if digital_only? mapped_values.uniq end |
#self_deposit_resource_types ⇒ Array<ResourceType>
ResourceType objects that are Stanford self-deposit resource types.
167 168 169 |
# File 'lib/cocina_display/concerns/forms.rb', line 167 def self_deposit_resource_types all_resource_types.filter { |resource_type| resource_type.stanford_self_deposit? } end |