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

Instance Method Details

#bare_druidString

The DRUID for the object, without the druid: prefix.

Examples:

record.bare_druid #=> "bb099mt5053"

Returns:

  • (String)


17
18
19
# File 'lib/cocina_display/concerns/identifiers.rb', line 17

def bare_druid
  druid.delete_prefix("druid:")
end

#doiString?

The DOI for the object, if there is one – just the identifier part.

Examples:

record.doi #=> "10.25740/ppax-bf07"

Returns:

  • (String, nil)


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_urlString?

The DOI as a URL, if there is one. Any valid DOI should resolve via doi.org.

Examples:

record.doi_url #=> "https://doi.org/10.25740/ppax-bf07"

Returns:

  • (String, nil)


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

#druidString

The DRUID for the object, with the druid: prefix.

Examples:

record.druid #=> "druid:bb099mt5053"

Returns:

  • (String)


9
10
11
# File 'lib/cocina_display/concerns/identifiers.rb', line 9

def druid
  cocina_doc["externalIdentifier"]
end

#folio_hrid(refresh: nil) ⇒ String?

Note:

This doesn’t imply the object is available in Searchworks at this ID.

The HRID of the item in FOLIO, if defined.

Examples:

With a link regardless of refresh:

record.folio_hrid #=> "a12845814"

With a link that is not refreshed:

record.folio_hrid(refresh: true) #=> nil

Parameters:

  • [Boolean] (refresh)

    Filter to links with refresh set to this value.

Returns:

  • (String, nil)


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_idString

Note:

This doesn’t imply the object is available in Searchworks at this ID.

The FOLIO HRID if defined, otherwise the bare DRUID.

Returns:

  • (String)

See Also:



63
64
65
# File 'lib/cocina_display/concerns/identifiers.rb', line 63

def searchworks_id
  folio_hrid || bare_druid
end