Module: CocinaDisplay::Concerns::Identifiers
- Included in:
- CocinaDisplay::CocinaRecord
- 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.
-
#searchworks_id ⇒ String
The FOLIO HRID if defined, otherwise the bare DRUID.
Instance Method Details
#bare_druid ⇒ String
The DRUID for the object, without the druid:
prefix.
17 18 19 |
# File 'lib/cocina_display/concerns/identifiers.rb', line 17 def druid.delete_prefix("druid:") end |
#doi ⇒ String?
The DOI for the object, if there is one – just the identifier part.
25 26 27 28 29 30 31 |
# File 'lib/cocina_display/concerns/identifiers.rb', line 25 def doi doi_id = path("$.identification.doi").first || path("$.description.identifier[?match(@.type, 'doi|DOI')].value").first || path("$.description.identifier[?search(@.uri, 'doi.org')].uri").first URI(doi_id).path.delete_prefix("/") if doi_id.present? end |
#doi_url ⇒ String?
The DOI as a URL, if there is one. Any valid DOI should resolve via doi.org.
37 38 39 |
# File 'lib/cocina_display/concerns/identifiers.rb', line 37 def doi_url URI.join("https://doi.org", doi).to_s if doi.present? end |
#druid ⇒ String
The DRUID for the object, with the druid:
prefix.
9 10 11 |
# File 'lib/cocina_display/concerns/identifiers.rb', line 9 def druid cocina_doc["externalIdentifier"] 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.
49 50 51 52 53 54 55 56 |
# File 'lib/cocina_display/concerns/identifiers.rb', line 49 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 |
#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.
63 64 65 |
# File 'lib/cocina_display/concerns/identifiers.rb', line 63 def searchworks_id folio_hrid || end |