cocina_display 1.4.3 → 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 +4 -4
- data/lib/cocina_display/cocina_record.rb +3 -6
- data/lib/cocina_display/concerns/contributors.rb +15 -2
- data/lib/cocina_display/concerns/forms.rb +13 -3
- data/lib/cocina_display/concerns/identifiers.rb +1 -0
- data/lib/cocina_display/concerns/structural.rb +7 -0
- data/lib/cocina_display/concerns/url_helpers.rb +33 -8
- data/lib/cocina_display/version.rb +1 -1
- metadata +3 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 90c6c88e6e77dc0d93ec05d8fb3a9b92bf5359609750a27b995a6da5fd1cc3bc
|
|
4
|
+
data.tar.gz: d92229bac2e2ffe80d9446e2e1e6ce286621d2218570c29acae543eaff07946b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b5861fb54b037cefe435a84f80ece667ecf48d1579ff29d548ca64e5bfcf0a51313eafb76b4d20a0145a625e9cf1406b7e2bb58dc16802a7d749f016e93ac5fb
|
|
7
|
+
data.tar.gz: 0a57cfb8965d62a653348694ad309e70a7f8771d13e6c5f3978dfaf50d4cfe6d87fb45f679621a67eb8cf1542688d52ad3b2e5ab4a7fa9f9c92787b1782a8b53
|
|
@@ -18,16 +18,14 @@ module CocinaDisplay
|
|
|
18
18
|
include CocinaDisplay::Concerns::RelatedResources
|
|
19
19
|
|
|
20
20
|
# Fetch a public Cocina document from PURL and create a CocinaRecord.
|
|
21
|
-
# @note This is intended to be used in development or testing only.
|
|
22
21
|
# @param druid [String] The bare DRUID of the object to fetch.
|
|
23
22
|
# @param purl_url [String] The base url for the purl service.
|
|
24
23
|
# @param deep_compact [Boolean] If true, compact the JSON to remove blank values.
|
|
25
24
|
# @return [CocinaDisplay::CocinaRecord]
|
|
26
|
-
# :nocov:
|
|
27
25
|
def self.fetch(druid, deep_compact: true, purl_url: "https://purl.stanford.edu")
|
|
28
|
-
|
|
26
|
+
response = Net::HTTP.get_response(URI("#{purl_url}/#{druid}.json"))
|
|
27
|
+
from_json(response.body, deep_compact: deep_compact) if response.is_a?(Net::HTTPSuccess)
|
|
29
28
|
end
|
|
30
|
-
# :nocov:
|
|
31
29
|
|
|
32
30
|
# Create a CocinaRecord from a JSON string.
|
|
33
31
|
# @param cocina_json [String]
|
|
@@ -53,13 +51,12 @@ module CocinaDisplay
|
|
|
53
51
|
end
|
|
54
52
|
|
|
55
53
|
# SDR content type of the object.
|
|
56
|
-
# @note {RelatedResource}s may not have a content type.
|
|
57
54
|
# @return [String, nil]
|
|
58
55
|
# @see https://github.com/sul-dlss/cocina-models/blob/main/openapi.yml#L532-L546
|
|
59
56
|
# @example
|
|
60
57
|
# record.content_type #=> "image"
|
|
61
58
|
def content_type
|
|
62
|
-
cocina_doc["type"]
|
|
59
|
+
cocina_doc["type"]&.delete_prefix("https://cocina.sul.stanford.edu/models/")
|
|
63
60
|
end
|
|
64
61
|
|
|
65
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>]
|
|
@@ -80,11 +86,11 @@ module CocinaDisplay
|
|
|
80
86
|
end
|
|
81
87
|
end
|
|
82
88
|
|
|
83
|
-
# DisplayData for Contributors, one per role.
|
|
89
|
+
# DisplayData for Contributors, one per role (excluding publisher).
|
|
84
90
|
# Contributors with no role are grouped under a default heading.
|
|
85
91
|
# @return [Array<DisplayData>]
|
|
86
92
|
def contributor_display_data
|
|
87
|
-
contributors_by_role.map do |role, contributors|
|
|
93
|
+
contributors_by_role.except("publisher").map do |role, contributors|
|
|
88
94
|
label = I18n.t(role, scope: "cocina_display.contributor.role",
|
|
89
95
|
default: role&.capitalize || I18n.t("default", scope: "cocina_display.contributor.role"))
|
|
90
96
|
DisplayData.new(label: label, objects: contributors)
|
|
@@ -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(
|
|
81
|
-
|
|
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 ||=
|
|
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
|
-
# @
|
|
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
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: cocina_display
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.6.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Nick Budak
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: exe
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date: 2025-
|
|
10
|
+
date: 2025-12-16 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: janeway-jsonpath
|
|
@@ -212,7 +211,6 @@ dependencies:
|
|
|
212
211
|
- - "~>"
|
|
213
212
|
- !ruby/object:Gem::Version
|
|
214
213
|
version: '3.1'
|
|
215
|
-
description:
|
|
216
214
|
email:
|
|
217
215
|
- budak@stanford.edu
|
|
218
216
|
executables: []
|
|
@@ -284,7 +282,6 @@ licenses:
|
|
|
284
282
|
metadata:
|
|
285
283
|
homepage_uri: https://sul-dlss.github.io/cocina_display/
|
|
286
284
|
source_code_uri: https://github.com/sul-dlss/cocina_display
|
|
287
|
-
post_install_message:
|
|
288
285
|
rdoc_options: []
|
|
289
286
|
require_paths:
|
|
290
287
|
- lib
|
|
@@ -299,8 +296,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
299
296
|
- !ruby/object:Gem::Version
|
|
300
297
|
version: '0'
|
|
301
298
|
requirements: []
|
|
302
|
-
rubygems_version: 3.
|
|
303
|
-
signing_key:
|
|
299
|
+
rubygems_version: 3.6.2
|
|
304
300
|
specification_version: 4
|
|
305
301
|
summary: Helpers for rendering Cocina metadata
|
|
306
302
|
test_files: []
|