cocina_display 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7faaded226886ab37cfbff854b64721c55964959089a1675706ae6160d4a1a5c
4
- data.tar.gz: 111b995bfdf70805eb7a613bf5f221bacf101be1ed3f9ad6fb2407266c7a35ab
3
+ metadata.gz: e2b164eda474dc396b74c8b911fe50bbba7c2dbbce17b29c24923db4f25ff8a5
4
+ data.tar.gz: c782186b53a4dcb7f53b11a3d552dcf5f892f4435fc46fb4bcddd65ad444d9be
5
5
  SHA512:
6
- metadata.gz: 6a8586d41059d8880ac29c48f564907a51b718dc7812f2314e564032e1f19722d97620755cd53f52aa927e17e45dbfab79b56936c022255f2c22c3147e2c110c
7
- data.tar.gz: 58ddd5de3cfe25d78904c24c1edaed72d4212eb7149b58b3b6e5c216390db75acc0c8ad81c039c9c712da99480842df2cab27c70573c848e2cb9377f0a31b909
6
+ metadata.gz: efed0c780617aaeadb7187391c74691bcacddcb24cb2850e14918ab755acfaef273c8e3277a9c4674b2b41201a72ffe91a79a0065daa07ad469e2178ea17fd92
7
+ data.tar.gz: 28933bab6be3f6cd2fed4155d5b4a73bf9f9d9301e5edc679018f6428d90f88ca14ab8a6614d1c07e53f1723644b0871786fb075b664bb7e2fb73dba96d21588
@@ -90,12 +90,13 @@ module CocinaDisplay
90
90
  end
91
91
 
92
92
  # SDR content type of the object.
93
- # @return [String]
93
+ # @note {RelatedResource}s may not have a content type.
94
+ # @return [String, nil]
94
95
  # @see https://github.com/sul-dlss/cocina-models/blob/main/openapi.yml#L532-L546
95
96
  # @example
96
97
  # record.content_type #=> "image"
97
98
  def content_type
98
- cocina_doc["type"].split("/").last
99
+ cocina_doc["type"]&.split("/")&.last
99
100
  end
100
101
 
101
102
  # Primary processing label for the object.
@@ -128,7 +129,7 @@ module CocinaDisplay
128
129
  attr_reader :type
129
130
 
130
131
  # Restructure the hash so that everything is under "description" key, since
131
- # it's all descriptive metadata. This makes CocinaRecord methods work.
132
+ # it's all descriptive metadata. This makes most CocinaRecord methods work.
132
133
  def initialize(cocina_doc)
133
134
  @type = cocina_doc["type"]
134
135
  @cocina_doc = {"description" => cocina_doc.except("type")}
@@ -7,30 +7,7 @@ module CocinaDisplay
7
7
  # @example
8
8
  # record.purl_url #=> "https://purl.stanford.edu/bx658jh7339"
9
9
  def purl_url
10
- cocina_doc.dig("description", "purl") || "https://purl.stanford.edu/#{bare_druid}"
11
- end
12
-
13
- # The URL to the PURL environment this object is from.
14
- # @note Objects accessed via UAT will still have a production PURL base URL.
15
- # @return [String]
16
- # @example
17
- # record.purl_base_url #=> "https://purl.stanford.edu"
18
- def purl_base_url
19
- URI(purl_url).origin
20
- end
21
-
22
- # The URL to the stacks environment this object is shelved in.
23
- # Corresponds to the PURL environment.
24
- # @see purl_base_url
25
- # @return [String]
26
- # @example
27
- # record.stacks_base_url #=> "https://stacks.stanford.edu"
28
- def stacks_base_url
29
- if purl_base_url == "https://sul-purl-stage.stanford.edu"
30
- "https://sul-stacks-stage.stanford.edu"
31
- else
32
- "https://stacks.stanford.edu"
33
- end
10
+ cocina_doc.dig("description", "purl") || ("https://purl.stanford.edu/#{bare_druid}" if bare_druid)
34
11
  end
35
12
 
36
13
  # The oEmbed URL for the object, optionally with additional parameters.
@@ -41,7 +18,7 @@ module CocinaDisplay
41
18
  # @example Generate an oEmbed URL for the viewer and hide the title
42
19
  # record.oembed_url(hide_title: true) #=> "https://purl.stanford.edu/bx658jh7339/embed.json?hide_title=true"
43
20
  def oembed_url(params: {})
44
- return if collection?
21
+ return if collection? || purl_url.blank?
45
22
 
46
23
  params[:url] ||= purl_url
47
24
  "#{purl_base_url}/embed.json?#{params.to_query}"
@@ -53,7 +30,7 @@ module CocinaDisplay
53
30
  # @example
54
31
  # record.download_url #=> "https://stacks.stanford.edu/object/bx658jh7339"
55
32
  def download_url
56
- "#{stacks_base_url}/object/#{bare_druid}"
33
+ "#{stacks_base_url}/object/#{bare_druid}" if bare_druid.present?
57
34
  end
58
35
 
59
36
  # The IIIF manifest URL for the object.
@@ -64,7 +41,32 @@ module CocinaDisplay
64
41
  # record.iiif_manifest_url #=> "https://purl.stanford.edu/bx658jh7339/iiif3/manifest"
65
42
  def iiif_manifest_url(version: 3)
66
43
  iiif_path = (version == 3) ? "iiif3" : "iiif"
67
- "#{purl_url}/#{iiif_path}/manifest"
44
+ "#{purl_url}/#{iiif_path}/manifest" if purl_url.present?
45
+ end
46
+
47
+ private
48
+
49
+ # The URL to the PURL environment this object is from.
50
+ # @note Objects accessed via UAT will still have a production PURL base URL.
51
+ # @return [String]
52
+ # @example
53
+ # record.purl_base_url #=> "https://purl.stanford.edu"
54
+ def purl_base_url
55
+ URI(purl_url).origin if purl_url.present?
56
+ end
57
+
58
+ # The URL to the stacks environment this object is shelved in.
59
+ # Corresponds to the PURL environment.
60
+ # @see purl_base_url
61
+ # @return [String]
62
+ # @example
63
+ # record.stacks_base_url #=> "https://stacks.stanford.edu"
64
+ def stacks_base_url
65
+ if purl_base_url == "https://sul-purl-stage.stanford.edu"
66
+ "https://sul-stacks-stage.stanford.edu"
67
+ elsif purl_base_url.present?
68
+ "https://stacks.stanford.edu"
69
+ end
68
70
  end
69
71
  end
70
72
  end
@@ -3,19 +3,22 @@ module CocinaDisplay
3
3
  # Methods for extracting and formatting identifiers from Cocina records.
4
4
  module Identifiers
5
5
  # The DRUID for the object, with the +druid:+ prefix.
6
- # @return [String]
6
+ # @note A {RelatedResource} may not have a DRUID.
7
+ # @return [String, nil]
7
8
  # @example
8
9
  # record.druid #=> "druid:bb099mt5053"
9
10
  def druid
10
- cocina_doc["externalIdentifier"]
11
+ cocina_doc["externalIdentifier"] ||
12
+ cocina_doc.dig("description", "purl")&.split("/")&.last
11
13
  end
12
14
 
13
15
  # The DRUID for the object, without the +druid:+ prefix.
14
- # @return [String]
16
+ # @note A {RelatedResource} may not have a DRUID.
17
+ # @return [String, nil]
15
18
  # @example
16
19
  # record.bare_druid #=> "bb099mt5053"
17
20
  def bare_druid
18
- druid.delete_prefix("druid:")
21
+ druid&.delete_prefix("druid:")
19
22
  end
20
23
 
21
24
  # The DOI for the object, if there is one – just the identifier part.
@@ -59,7 +62,7 @@ module CocinaDisplay
59
62
  # @note This doesn't imply the object is available in Searchworks at this ID.
60
63
  # @see folio_hrid
61
64
  # @see bare_druid
62
- # @return [String]
65
+ # @return [String, nil]
63
66
  def searchworks_id
64
67
  folio_hrid || bare_druid
65
68
  end
@@ -99,6 +99,8 @@ module CocinaDisplay
99
99
  # this may be useful for boosting and exact matching for search results
100
100
  # @return [Array<String>] the main title value(s) for Solr - can be array due to parallel titles
101
101
  def main_title(titles)
102
+ return [] if titles.empty?
103
+
102
104
  cocina_title = primary_title(titles) || untyped_title(titles)
103
105
  cocina_title = other_title(titles) if cocina_title.blank?
104
106
 
@@ -2,5 +2,5 @@
2
2
 
3
3
  # :nodoc:
4
4
  module CocinaDisplay
5
- VERSION = "1.1.0" # :nodoc:
5
+ VERSION = "1.1.1" # :nodoc:
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cocina_display
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Budak