Class: CocinaDisplay::CocinaRecord
- Inherits:
-
Object
- Object
- CocinaDisplay::CocinaRecord
- Includes:
- CocinaDisplay::Concerns::Access, CocinaDisplay::Concerns::Contributors, CocinaDisplay::Concerns::Events, CocinaDisplay::Concerns::Forms, CocinaDisplay::Concerns::Identifiers, CocinaDisplay::Concerns::Languages, CocinaDisplay::Concerns::Subjects, CocinaDisplay::Concerns::Titles
- Defined in:
- lib/cocina_display/cocina_record.rb
Overview
Public Cocina metadata for an SDR object, as fetched from PURL.
Instance Attribute Summary collapse
-
#cocina_doc ⇒ Hash
readonly
The parsed Cocina document.
Class Method Summary collapse
-
.fetch(druid, deep_compact: false) ⇒ CocinaDisplay::CocinaRecord
Fetch a public Cocina document from PURL and create a CocinaRecord.
-
.from_json(cocina_json, deep_compact: false) ⇒ CocinaDisplay::CocinaRecord
Create a CocinaRecord from a JSON string.
Instance Method Summary collapse
-
#collection? ⇒ Boolean
True if the object is a collection.
-
#content_type ⇒ String
SDR content type of the object.
-
#created_time ⇒ Time
Timestamp when the Cocina was created.
-
#files ⇒ Enumerator
Traverse nested FileSets and return an enumerator over their files.
-
#initialize(cocina_doc) ⇒ CocinaRecord
constructor
Initialize a CocinaRecord with a Cocina document hash.
-
#label ⇒ String?
Primary processing label for the object.
-
#modified_time ⇒ Time
Timestamp when the Cocina was last modified.
-
#path(path_expression) ⇒ Enumerator
Evaluate a JSONPath expression against the Cocina document.
Methods included from CocinaDisplay::Concerns::Languages
#languages, #searchworks_language_names
Methods included from CocinaDisplay::Concerns::Forms
#archived_website?, #cartographic?, #dataset?, #extents, #forms, #genres, #genres_search, #periodical?, #resource_types
Methods included from CocinaDisplay::Concerns::Subjects
#subject_all, #subject_all_display, #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::Access
#download_url, #iiif_manifest_url, #oembed_url, #purl_base_url, #purl_url, #stacks_base_url
Methods included from CocinaDisplay::Concerns::Titles
#additional_titles, #display_title, #full_title, #main_title, #sort_title
Methods included from CocinaDisplay::Concerns::Identifiers
#bare_druid, #doi, #doi_url, #druid, #folio_hrid, #searchworks_id
Methods included from CocinaDisplay::Concerns::Contributors
#additional_contributor_names, #additional_contributors, #conference_contributor_names, #contributor_names_by_role, #contributors, #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
#earliest_preferred_date, #event_dates, #events, #imprint_display_str, #imprint_events, #pub_date, #pub_date_edtf, #pub_year_display_str, #pub_year_int, #pub_year_int_range, #publication_events, #publication_places
Constructor Details
#initialize(cocina_doc) ⇒ CocinaRecord
Initialize a CocinaRecord with a Cocina document hash.
58 59 60 |
# File 'lib/cocina_display/cocina_record.rb', line 58 def initialize(cocina_doc) @cocina_doc = cocina_doc end |
Instance Attribute Details
#cocina_doc ⇒ Hash (readonly)
The parsed Cocina document.
54 55 56 |
# File 'lib/cocina_display/cocina_record.rb', line 54 def cocina_doc @cocina_doc end |
Class Method Details
.fetch(druid, deep_compact: false) ⇒ CocinaDisplay::CocinaRecord
This is intended to be used in development or testing only.
Fetch a public Cocina document from PURL and create a CocinaRecord. :nocov:
38 39 40 |
# File 'lib/cocina_display/cocina_record.rb', line 38 def self.fetch(druid, deep_compact: false) 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.
47 48 49 50 |
# File 'lib/cocina_display/cocina_record.rb', line 47 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.
106 107 108 |
# File 'lib/cocina_display/cocina_record.rb', line 106 def collection? content_type == "collection" end |
#content_type ⇒ String
SDR content type of the object.
93 94 95 |
# File 'lib/cocina_display/cocina_record.rb', line 93 def content_type cocina_doc["type"].split("/").last end |
#created_time ⇒ Time
This is for the metadata itself, not the object.
Timestamp when the Cocina was created.
77 78 79 |
# File 'lib/cocina_display/cocina_record.rb', line 77 def created_time Time.parse(cocina_doc["created"]) end |
#files ⇒ Enumerator
Traverse nested FileSets and return an enumerator over their files. Each file is a Hash
.
118 119 120 |
# File 'lib/cocina_display/cocina_record.rb', line 118 def files path("$.structural.contains.*.structural.contains[*]") end |
#label ⇒ String?
This may or may not be the same as the title.
Primary processing label for the object.
100 101 102 |
# File 'lib/cocina_display/cocina_record.rb', line 100 def label cocina_doc["label"] end |
#modified_time ⇒ Time
This is for the metadata itself, not the object.
Timestamp when the Cocina was last modified.
84 85 86 |
# File 'lib/cocina_display/cocina_record.rb', line 84 def modified_time Time.parse(cocina_doc["modified"]) end |
#path(path_expression) ⇒ Enumerator
Evaluate a JSONPath expression against the Cocina document.
70 71 72 |
# File 'lib/cocina_display/cocina_record.rb', line 70 def path(path_expression) Janeway.enum_for(path_expression, cocina_doc) end |