cocina_display 1.5.0 → 1.6.0

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: 9f613a3974d14946081f09d45797c2be75475c2b37fedf4ebe51a9c7eef2de10
4
- data.tar.gz: 6dc64d8348e652ac4bea87a904519029ed580cc498c6e584d2a196a079293141
3
+ metadata.gz: 90c6c88e6e77dc0d93ec05d8fb3a9b92bf5359609750a27b995a6da5fd1cc3bc
4
+ data.tar.gz: d92229bac2e2ffe80d9446e2e1e6ce286621d2218570c29acae543eaff07946b
5
5
  SHA512:
6
- metadata.gz: 56874880d8a3fff624afb2306aeffab7792b59f678901a5f8632bd77beca3eeaab388053ddcc3790d6f1c5dfe687ee6588cd83eafe5cc143893eb8d551ed617f
7
- data.tar.gz: d39907bb6d250a06ab01b5127fc98223ac6225e2e346ea9eaadaa91874ff20b807e2ded45453e5ed10cfb9515eba4b3da11ab5fb8ee7b42718ac670ab4cde95f
6
+ metadata.gz: b5861fb54b037cefe435a84f80ece667ecf48d1579ff29d548ca64e5bfcf0a51313eafb76b4d20a0145a625e9cf1406b7e2bb58dc16802a7d749f016e93ac5fb
7
+ data.tar.gz: 0a57cfb8965d62a653348694ad309e70a7f8771d13e6c5f3978dfaf50d4cfe6d87fb45f679621a67eb8cf1542688d52ad3b2e5ab4a7fa9f9c92787b1782a8b53
@@ -51,13 +51,12 @@ module CocinaDisplay
51
51
  end
52
52
 
53
53
  # SDR content type of the object.
54
- # @note {RelatedResource}s may not have a content type.
55
54
  # @return [String, nil]
56
55
  # @see https://github.com/sul-dlss/cocina-models/blob/main/openapi.yml#L532-L546
57
56
  # @example
58
57
  # record.content_type #=> "image"
59
58
  def content_type
60
- cocina_doc["type"].delete_prefix("https://cocina.sul.stanford.edu/models/")
59
+ cocina_doc["type"]&.delete_prefix("https://cocina.sul.stanford.edu/models/")
61
60
  end
62
61
 
63
62
  # Primary processing label for the object.
@@ -27,6 +27,12 @@ module CocinaDisplay
27
27
  publisher_contributors.flat_map(&:display_names).compact
28
28
  end
29
29
 
30
+ # All names of authors, formatted for display.
31
+ # @return [Array<String>]
32
+ def author_names
33
+ author_contributors.flat_map(&:display_names).compact
34
+ end
35
+
30
36
  # All names of contributors who are people, formatted for display.
31
37
  # @param with_date [Boolean] Include life dates, if present
32
38
  # @return [Array<String>]
@@ -111,6 +117,13 @@ module CocinaDisplay
111
117
  ).map { |c| CocinaDisplay::Contributors::Contributor.new(c) }
112
118
  end
113
119
 
120
+ # All contributors with an "author" role.
121
+ # @return [Array<Contributor>]
122
+ # @see Contributor#author?
123
+ def author_contributors
124
+ contributors.filter(&:author?)
125
+ end
126
+
114
127
  # All contributors with a "publisher" role.
115
128
  # @return [Array<Contributor>]
116
129
  # @see Contributor#publisher?
@@ -75,10 +75,16 @@ module CocinaDisplay
75
75
  end
76
76
 
77
77
  # All form notes to be rendered for display.
78
+ # Checks both description.form.note and description.geographic.form.note.
78
79
  # @return [Array<DisplayData>]
79
80
  def form_note_display_data
80
- CocinaDisplay::DisplayData.from_cocina(path("$.description.form[*].note[*]"),
81
- label: I18n.t("cocina_display.field_label.form.note"))
81
+ CocinaDisplay::DisplayData.from_cocina(
82
+ Enumerator::Chain.new(
83
+ path("$.description.form.*.note.*"),
84
+ path("$.description.geographic.*.form.*.note.*")
85
+ ),
86
+ label: I18n.t("cocina_display.field_label.form.note")
87
+ )
82
88
  end
83
89
 
84
90
  # Is the object a periodical or serial?
@@ -106,10 +112,14 @@ module CocinaDisplay
106
112
  end
107
113
 
108
114
  # Collapses all nested form values into an array of {Form} objects.
115
+ # Checks both description.form and description.geographic.form.
109
116
  # Preserves resource type without flattening, since it can be structured.
110
117
  # @return [Array<Form>]
111
118
  def all_forms
112
- @all_forms ||= path("$.description.form.*")
119
+ @all_forms ||= Enumerator::Chain.new(
120
+ path("$.description.form.*"),
121
+ path("$.description.geographic.*.form.*")
122
+ )
113
123
  .flat_map { |form| Utils.flatten_nested_values(form, atomic_types: ["resource type"]) }
114
124
  .map { |form| CocinaDisplay::Forms::Form.from_cocina(form) }
115
125
  end
@@ -36,6 +36,13 @@ module CocinaDisplay
36
36
  def total_file_size_int
37
37
  files.pluck("size").sum
38
38
  end
39
+
40
+ # DRUIDs of collections this object is a member of.
41
+ # @return [Array<String>]
42
+ # @example ["sj775xm6965"]
43
+ def containing_collections
44
+ path("$.structural.isMemberOf.*").map { |druid| druid.delete_prefix("druid:") }
45
+ end
39
46
  end
40
47
  end
41
48
  end
@@ -3,7 +3,7 @@ module CocinaDisplay
3
3
  # Methods that generate URLs to access an object.
4
4
  module UrlHelpers
5
5
  # The PURL URL for this object.
6
- # @return [String]
6
+ # @return [String, nil]
7
7
  # @example
8
8
  # record.purl_url #=> "https://purl.stanford.edu/bx658jh7339"
9
9
  def purl_url
@@ -13,8 +13,7 @@ module CocinaDisplay
13
13
  # The oEmbed URL for the object, optionally with additional parameters.
14
14
  # Corresponds to the PURL environment.
15
15
  # @param params [Hash] Additional parameters to include in the oEmbed URL.
16
- # @return [String]
17
- # @return [nil] if the object is a collection.
16
+ # @return [String, nil]
18
17
  # @example Generate an oEmbed URL for the viewer and hide the title
19
18
  # record.oembed_url(hide_title: true) #=> "https://purl.stanford.edu/bx658jh7339/embed.json?hide_title=true"
20
19
  def oembed_url(params: {})
@@ -26,17 +25,18 @@ module CocinaDisplay
26
25
 
27
26
  # The download URL to get the entire object as a .zip file.
28
27
  # Stacks generates the .zip for the object on request.
29
- # @return [String]
28
+ # @note Collections and related resources do not have a download URL.
29
+ # @return [String, nil]
30
30
  # @example
31
31
  # record.download_url #=> "https://stacks.stanford.edu/object/bx658jh7339"
32
32
  def download_url
33
- "#{stacks_base_url}/object/#{bare_druid}" if bare_druid.present?
33
+ "#{stacks_base_url}/object/#{bare_druid}" if is_a?(CocinaDisplay::CocinaRecord) && bare_druid.present? && !collection?
34
34
  end
35
35
 
36
36
  # The IIIF manifest URL for the object.
37
37
  # PURL generates the IIIF manifest.
38
38
  # @param version [Integer] The IIIF presentation spec version to use (3 or 2).
39
- # @return [String]
39
+ # @return [String, nil]
40
40
  # @example
41
41
  # record.iiif_manifest_url #=> "https://purl.stanford.edu/bx658jh7339/iiif3/manifest"
42
42
  def iiif_manifest_url(version: 3)
@@ -44,11 +44,22 @@ module CocinaDisplay
44
44
  "#{purl_url}/#{iiif_path}/manifest" if purl_url.present?
45
45
  end
46
46
 
47
+ # The Searchworks URL for this object.
48
+ # Uses the catkey (FOLIO HRID) if present, otherwise uses the druid.
49
+ # @note This does not guarantee that the object is actually in Searchworks.
50
+ # @return [String, nil]
51
+ # @example
52
+ # record.searchworks_url #=> "https://searchworks.stanford.edu/view/bx658jh7339"
53
+ def searchworks_url
54
+ return "#{searchworks_base_url}/view/#{folio_hrid}" if folio_hrid.present?
55
+ "#{searchworks_base_url}/view/#{bare_druid}" if bare_druid.present?
56
+ end
57
+
47
58
  private
48
59
 
49
60
  # The URL to the PURL environment this object is from.
50
61
  # @note Objects accessed via UAT will still have a production PURL base URL.
51
- # @return [String]
62
+ # @return [String, nil]
52
63
  # @example
53
64
  # record.purl_base_url #=> "https://purl.stanford.edu"
54
65
  def purl_base_url
@@ -58,7 +69,7 @@ module CocinaDisplay
58
69
  # The URL to the stacks environment this object is shelved in.
59
70
  # Corresponds to the PURL environment.
60
71
  # @see purl_base_url
61
- # @return [String]
72
+ # @return [String, nil]
62
73
  # @example
63
74
  # record.stacks_base_url #=> "https://stacks.stanford.edu"
64
75
  def stacks_base_url
@@ -68,6 +79,20 @@ module CocinaDisplay
68
79
  "https://stacks.stanford.edu"
69
80
  end
70
81
  end
82
+
83
+ # The URL to the Searchworks environment this object could be found in.
84
+ # Corresponds to the PURL environment.
85
+ # @see purl_base_url
86
+ # @return [String, nil]
87
+ # @example
88
+ # record.searchworks_base_url #=> "https://searchworks.stanford.edu"
89
+ def searchworks_base_url
90
+ if purl_base_url == "https://sul-purl-stage.stanford.edu"
91
+ "https://searchworks-stage.stanford.edu"
92
+ elsif purl_base_url.present?
93
+ "https://searchworks.stanford.edu"
94
+ end
95
+ end
71
96
  end
72
97
  end
73
98
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  # :nodoc:
4
4
  module CocinaDisplay
5
- VERSION = "1.5.0" # :nodoc:
5
+ VERSION = "1.6.0" # :nodoc:
6
6
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cocina_display
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Budak
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-12-05 00:00:00.000000000 Z
10
+ date: 2025-12-16 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: janeway-jsonpath