Class: CocinaDisplay::CocinaRecord

Overview

Public Cocina metadata for an SDR object, as fetched from PURL.

Instance Attribute Summary

Attributes inherited from JsonBackedRecord

#cocina_doc

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CocinaDisplay::Concerns::RelatedResources

#related_resource_display_data, #related_resources

Methods included from CocinaDisplay::Concerns::Structural

#file_mime_types, #files, #total_file_size_int, #total_file_size_str

Methods included from CocinaDisplay::Concerns::Geospatial

#coordinates, #coordinates_as_envelope, #coordinates_as_point, #coordinates_as_wkt, #geonames_ids

Methods included from CocinaDisplay::Concerns::Languages

#language_display_data, #languages, #searchworks_language_names

Methods included from CocinaDisplay::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 CocinaDisplay::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 CocinaDisplay::Concerns::UrlHelpers

#download_url, #iiif_manifest_url, #oembed_url, #purl_url

Methods included from CocinaDisplay::Concerns::Titles

#additional_titles, #all_titles, #display_title, #full_title, #main_title, #primary_title, #secondary_titles, #sort_title, #title_display_data

Methods included from CocinaDisplay::Concerns::Notes

#abstract_display_data, #general_note_display_data, #notes, #preferred_citation_display_data, #table_of_contents_display_data

Methods included from CocinaDisplay::Concerns::Identifiers

#bare_druid, #doi, #doi_url, #druid, #folio_hrid, #identifier_display_data, #identifiers, #searchworks_id

Methods included from CocinaDisplay::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 CocinaDisplay::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 CocinaDisplay::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

#initialize, #path

Constructor Details

This class inherits a constructor from CocinaDisplay::JsonBackedRecord

Class Method Details

.fetch(druid, deep_compact: true) ⇒ CocinaDisplay::CocinaRecord

Note:

This is intended to be used in development or testing only.

Fetch a public Cocina document from PURL and create a CocinaRecord. :nocov:

Parameters:

  • druid (String)

    The bare DRUID of the object to fetch.

  • deep_compact (Boolean) (defaults to: true)

    If true, compact the JSON to remove blank values.

Returns:



26
27
28
# File 'lib/cocina_display/cocina_record.rb', line 26

def self.fetch(druid, deep_compact: true)
  from_json(Net::HTTP.get(URI("https://purl.stanford.edu/#{druid}.json")), deep_compact: deep_compact)
end

.from_json(cocina_json, deep_compact: false) ⇒ CocinaDisplay::CocinaRecord

Create a CocinaRecord from a JSON string.

Parameters:

  • cocina_json (String)
  • deep_compact (Boolean) (defaults to: false)

    If true, compact the JSON to remove blank values.

Returns:



35
36
37
38
# File 'lib/cocina_display/cocina_record.rb', line 35

def self.from_json(cocina_json, deep_compact: false)
  cocina_doc = JSON.parse(cocina_json)
  deep_compact ? new(Utils.deep_compact_blank(cocina_doc)) : new(cocina_doc)
end

Instance Method Details

#collection?Boolean

True if the object is a collection.

Returns:

  • (Boolean)


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

def collection?
  content_type == "collection"
end

#content_typeString?

Note:

RelatedResources may not have a content type.

SDR content type of the object.

Examples:

record.content_type #=> "image"

Returns:

  • (String, nil)

See Also:



60
61
62
# File 'lib/cocina_display/cocina_record.rb', line 60

def content_type
  cocina_doc["type"].delete_prefix("https://cocina.sul.stanford.edu/models/")
end

Copyright statement from Cocina access metadata.

Returns:

  • (String, nil)


79
80
81
# File 'lib/cocina_display/cocina_record.rb', line 79

def copyright
  cocina_doc.dig("access", "copyright")
end

#created_timeTime

Note:

This is for the metadata itself, not the object.

Timestamp when the Cocina was created.

Returns:

  • (Time)


43
44
45
# File 'lib/cocina_display/cocina_record.rb', line 43

def created_time
  Time.parse(cocina_doc["created"])
end

#labelString?

Note:

This may or may not be the same as the title.

Primary processing label for the object.

Returns:

  • (String, nil)


67
68
69
# File 'lib/cocina_display/cocina_record.rb', line 67

def label
  cocina_doc["label"]
end

#licenseString?

License URI

Returns:

  • (String, nil)


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

def license
  cocina_doc.dig("access", "license")
end

#license_descriptionString?

Description of the license

Returns:

  • (String, nil)


91
92
93
94
# File 'lib/cocina_display/cocina_record.rb', line 91

def license_description
  @license_description ||=
    license ? License.new(url: license).description : nil
end

#modified_timeTime

Note:

This is for the metadata itself, not the object.

Timestamp when the Cocina was last modified.

Returns:

  • (Time)


50
51
52
# File 'lib/cocina_display/cocina_record.rb', line 50

def modified_time
  Time.parse(cocina_doc["modified"])
end

#use_and_reproductionString?

Use and reproduction statement from Cocina access metadata.

Returns:

  • (String, nil)


85
86
87
# File 'lib/cocina_display/cocina_record.rb', line 85

def use_and_reproduction
  cocina_doc.dig("access", "useAndReproductionStatement")
end