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
-
#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.
-
#folio_hrid(refresh: nil) ⇒ String?
(also: #catkey)
The HRID of the item in FOLIO, if defined.
-
#identifier_display_data ⇒ Array<DisplayData>
Labelled display data for identifiers.
-
#identifiers(type: nil) ⇒ Array<Identifier>
All identifier objects, optionally filtered by type.
-
#searchworks_id ⇒ String?
The FOLIO HRID if defined, otherwise the bare DRUID.
Instance Method Details
#doi ⇒ String?
The DOI for the object, if there is one – just the identifier part.
9 10 11 |
# File 'lib/cocina_display/concerns/identifiers.rb', line 9 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.
17 18 19 |
# File 'lib/cocina_display/concerns/identifiers.rb', line 17 def doi_url URI.join("https://doi.org", doi).to_s if doi.present? end |
#folio_hrid(refresh: nil) ⇒ String? Also known as: catkey
This doesn’t imply the object is available in Searchworks at this ID.
The HRID of the item in FOLIO, if defined.
29 30 31 32 33 34 35 36 |
# File 'lib/cocina_display/concerns/identifiers.rb', line 29 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.
58 59 60 |
# File 'lib/cocina_display/concerns/identifiers.rb', line 58 def identifier_display_data CocinaDisplay::DisplayData.from_objects(identifiers) end |
#identifiers(type: nil) ⇒ Array<Identifier>
Type matching is case insensitive.
All identifier objects, optionally filtered by type.
52 53 54 |
# File 'lib/cocina_display/concerns/identifiers.rb', line 52 def identifiers(type: nil) type.present? ? all_identifiers.filter { |id| id.type&.casecmp?(type) } : all_identifiers 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.
44 45 46 |
# File 'lib/cocina_display/concerns/identifiers.rb', line 44 def searchworks_id folio_hrid || end |