Class: CocinaDisplay::RelatedResource
- Inherits:
-
JsonBackedRecord
- Object
- JsonBackedRecord
- CocinaDisplay::RelatedResource
- Includes:
- Concerns::Accesses, Concerns::Contributors, Concerns::Events, Concerns::Forms, Concerns::Geospatial, Concerns::Identifiers, Concerns::Languages, Concerns::Notes, Concerns::Subjects, Concerns::Titles, Concerns::UrlHelpers
- Defined in:
- lib/cocina_display/related_resource.rb
Overview
Related resources have no structural metadata.
A resource related to the record. See github.com/sul-dlss/cocina-models/blob/main/lib/cocina/models/related_resource.rb
Instance Attribute Summary collapse
-
#type ⇒ String
readonly
Description of the relation to the source record.
Attributes inherited from JsonBackedRecord
Instance Method Summary collapse
-
#display_data ⇒ Array<DisplayData>
Nested display data for the related resource.
-
#initialize(cocina_doc) ⇒ RelatedResource
constructor
Restructure the hash so that everything is under “description” key, since it’s all descriptive metadata.
-
#label ⇒ String
Label used to group the related resource for display.
-
#to_s ⇒ String?
String representation of the related resource.
-
#url ⇒ String?
URL to the related resource for link construction.
-
#url? ⇒ Boolean
Is this a related resource with a URL?.
Methods included from Concerns::Geospatial
#coordinates, #coordinates_as_envelope, #coordinates_as_point, #coordinates_as_wkt, #geonames_ids
Methods included from Concerns::Languages
#language_display_data, #languages, #searchworks_language_names
Methods included from Concerns::Forms
#archived_website?, #cartographic?, #dataset?, #extents, #form_display_data, #form_note_display_data, #forms, #genre_display_data, #genres, #genres_search, #map_display_data, #mods_resource_types, #periodical?, #searchworks_resource_types
Methods included from Concerns::Subjects
#subject_all, #subject_all_display, #subject_display_data, #subject_genres, #subject_names, #subject_occupations, #subject_other, #subject_places, #subject_temporal, #subject_temporal_genre, #subject_titles, #subject_topics, #subject_topics_other
Methods included from Concerns::UrlHelpers
#download_url, #iiif_manifest_url, #oembed_url, #purl_url
Methods included from Concerns::Titles
#additional_titles, #all_titles, #display_title, #full_title, #main_title, #primary_title, #secondary_titles, #sort_title, #title_display_data
Methods included from Concerns::Notes
#abstract_display_data, #general_note_display_data, #notes, #preferred_citation_display_data, #table_of_contents_display_data
Methods included from Concerns::Identifiers
#bare_druid, #doi, #doi_url, #druid, #folio_hrid, #identifier_display_data, #identifiers, #searchworks_id
Methods included from Concerns::Contributors
#additional_contributor_names, #additional_contributors, #conference_contributor_names, #contributor_display_data, #contributor_names_by_role, #contributors, #contributors_by_role, #impersonal_contributor_names, #main_contributor, #main_contributor_name, #organization_contributor_names, #person_contributor_names, #publisher_contributors, #publisher_names, #sort_contributor_name
Methods included from Concerns::Events
#admin_creation_event, #earliest_preferred_date, #event_date_display_data, #event_dates, #event_note_display_data, #events, #imprint_events, #imprint_str, #pub_date, #pub_date_edtf, #pub_year_int, #pub_year_int_range, #pub_year_str, #publication_events, #publication_places
Methods included from Concerns::Accesses
#access_contacts, #access_display_data, #accesses, #contact_email_display_data, #copyright_display_data, #license_display_data, #urls, #use_and_reproduction_display_data
Methods inherited from JsonBackedRecord
Constructor Details
#initialize(cocina_doc) ⇒ RelatedResource
Restructure the hash so that everything is under “description” key, since it’s all descriptive metadata. This makes most CocinaRecord methods work.
27 28 29 30 |
# File 'lib/cocina_display/related_resource.rb', line 27 def initialize(cocina_doc) @type = cocina_doc["type"] super({"description" => cocina_doc.except("type")}) end |
Instance Attribute Details
#type ⇒ String (readonly)
Description of the relation to the source record.
23 24 25 |
# File 'lib/cocina_display/related_resource.rb', line 23 def type @type end |
Instance Method Details
#display_data ⇒ Array<DisplayData>
Used for extended display of citations, e.g. on hp566jq8781.
Nested display data for the related resource. Combines titles, contributors, notes, and access information.
61 62 63 |
# File 'lib/cocina_display/related_resource.rb', line 61 def display_data title_display_data + contributor_display_data + general_note_display_data + preferred_citation_display_data + access_display_data end |
#label ⇒ String
Label used to group the related resource for display.
34 35 36 |
# File 'lib/cocina_display/related_resource.rb', line 34 def label cocina_doc.dig("description", "displayLabel").presence || type_label end |
#to_s ⇒ String?
String representation of the related resource.
40 41 42 |
# File 'lib/cocina_display/related_resource.rb', line 40 def to_s main_title || url end |
#url ⇒ String?
URL to the related resource for link construction. If there are multiple URLs, uses the first.
47 48 49 |
# File 'lib/cocina_display/related_resource.rb', line 47 def url urls.first&.to_s || purl_url end |
#url? ⇒ Boolean
Is this a related resource with a URL?
53 54 55 |
# File 'lib/cocina_display/related_resource.rb', line 53 def url? url.present? end |