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

Instance Method Details

#bare_druidString?

Note:

A RelatedResource may not have a DRUID.

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

Examples:

record.bare_druid #=> "bb099mt5053"

Returns:

  • (String, nil)


20
21
22
# File 'lib/cocina_display/concerns/identifiers.rb', line 20

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)


28
29
30
# File 'lib/cocina_display/concerns/identifiers.rb', line 28

def doi
  identifiers.find(&:doi?)&.identifier
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)


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

#druidString?

Note:

A RelatedResource may not have a DRUID.

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

Examples:

record.druid #=> "druid:bb099mt5053"

Returns:

  • (String, nil)


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?

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)


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_dataArray<DisplayData>

Labelled display data for identifiers.

Returns:



74
75
76
# File 'lib/cocina_display/concerns/identifiers.rb', line 74

def identifier_display_data
  CocinaDisplay::DisplayData.from_objects(identifiers)
end

#identifiersArray<Identifier>

Identifier objects extracted from the Cocina metadata.

Returns:



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_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, nil)

See Also:



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

def searchworks_id
  folio_hrid || bare_druid
end