Module: CocinaDisplay::Concerns::Identifiers
- Included in:
- CocinaDisplay::CocinaRecord, RelatedResource
- Defined in:
- lib/cocina_display/concerns/identifiers.rb
Overview
Methods for extracting and formatting identifiers from Cocina records.
Instance Method Summary collapse
-
#bare_druid ⇒ String?
The DRUID for the object, without the
druid:
prefix. -
#doi ⇒ String?
The DOI for the object, if there is one – just the identifier part.
-
#doi_url ⇒ String?
The DOI as a URL, if there is one.
-
#druid ⇒ String?
The DRUID for the object, with the
druid:
prefix. -
#folio_hrid(refresh: nil) ⇒ String?
The HRID of the item in FOLIO, if defined.
-
#identifier_display_data ⇒ Array<DisplayData>
Labelled display data for identifiers.
-
#identifiers ⇒ Array<Identifier>
Identifier objects extracted from the Cocina metadata.
-
#searchworks_id ⇒ String?
The FOLIO HRID if defined, otherwise the bare DRUID.
Instance Method Details
#bare_druid ⇒ String?
A RelatedResource may not have a DRUID.
The DRUID for the object, without the druid:
prefix.
20 21 22 |
# File 'lib/cocina_display/concerns/identifiers.rb', line 20 def druid&.delete_prefix("druid:") end |
#doi ⇒ String?
The DOI for the object, if there is one – just the identifier part.
28 29 30 |
# File 'lib/cocina_display/concerns/identifiers.rb', line 28 def doi identifiers.find(&:doi?)&.identifier end |
#doi_url ⇒ String?
The DOI as a URL, if there is one. Any valid DOI should resolve via doi.org.
36 37 38 |
# File 'lib/cocina_display/concerns/identifiers.rb', line 36 def doi_url URI.join("https://doi.org", doi).to_s if doi.present? end |
#druid ⇒ String?
A RelatedResource may not have a DRUID.
The DRUID for the object, with the druid:
prefix.
10 11 12 13 |
# File 'lib/cocina_display/concerns/identifiers.rb', line 10 def druid cocina_doc["externalIdentifier"] || cocina_doc.dig("description", "purl")&.split("/")&.last end |
#folio_hrid(refresh: nil) ⇒ String?
This doesn’t imply the object is available in Searchworks at this ID.
The HRID of the item in FOLIO, if defined.
48 49 50 51 52 53 54 55 |
# File 'lib/cocina_display/concerns/identifiers.rb', line 48 def folio_hrid(refresh: nil) link = path("$.identification.catalogLinks[?(@.catalog == 'folio')]").first hrid = link&.dig("catalogRecordId") return if hrid.blank? return hrid if refresh.nil? (link["refresh"] == refresh) ? hrid : nil end |
#identifier_display_data ⇒ Array<DisplayData>
Labelled display data for identifiers.
74 75 76 |
# File 'lib/cocina_display/concerns/identifiers.rb', line 74 def identifier_display_data CocinaDisplay::DisplayData.from_objects(identifiers) end |
#identifiers ⇒ Array<Identifier>
Identifier objects extracted from the Cocina metadata.
68 69 70 |
# File 'lib/cocina_display/concerns/identifiers.rb', line 68 def identifiers @identifiers ||= path("$.description.identifier[*]").map { |id| Identifier.new(id) } + Array(doi_from_identification) end |
#searchworks_id ⇒ String?
This doesn’t imply the object is available in Searchworks at this ID.
The FOLIO HRID if defined, otherwise the bare DRUID.
62 63 64 |
# File 'lib/cocina_display/concerns/identifiers.rb', line 62 def searchworks_id folio_hrid || end |