cocina_display 1.1.0 → 1.1.2
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 +4 -3
- data/lib/cocina_display/concerns/access.rb +29 -27
- data/lib/cocina_display/concerns/identifiers.rb +8 -5
- data/lib/cocina_display/dates/date.rb +13 -8
- data/lib/cocina_display/dates/date_range.rb +10 -1
- data/lib/cocina_display/title_builder.rb +2 -0
- data/lib/cocina_display/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6eddb643cc7413aaefd5b2b73df29c7d9aaa98ce7a0008816d405c82f73517d
|
4
|
+
data.tar.gz: 0ce368a036754577ab65e1f917750f4b6142d48bcb413eb202a4538324fca2ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e1a2cff79e052b77dfa25a84ac2899b21143342fdbff2b16c12a8f059c15b7a3cbfbb75b6daf52db21778989aea4beab60c35ad590f1ce4badea4ed7322f3876
|
7
|
+
data.tar.gz: 52f9cb5bba2e219da180275de8c2db31e82e4dfea8bc72987be4ccaaa4239007af4491f8db2f2633e03cf2cc4141d6963483f408740dfdeeb8f03ef661c14a0c
|
@@ -90,12 +90,13 @@ module CocinaDisplay
|
|
90
90
|
end
|
91
91
|
|
92
92
|
# SDR content type of the object.
|
93
|
-
# @
|
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"]
|
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
|
-
# @
|
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
|
-
# @
|
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
|
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
|
@@ -37,6 +37,7 @@ module CocinaDisplay
|
|
37
37
|
# Try to match against known date formats using their regexes
|
38
38
|
# Order matters here; more specific formats should be checked first
|
39
39
|
date_class ||= [
|
40
|
+
UndeclaredEdtfFormat,
|
40
41
|
MMDDYYYYFormat,
|
41
42
|
MMDDYYFormat,
|
42
43
|
YearRangeFormat,
|
@@ -86,10 +87,16 @@ module CocinaDisplay
|
|
86
87
|
# @return [String, nil]
|
87
88
|
attr_accessor :type
|
88
89
|
|
90
|
+
# The encoding name of this date, if specified.
|
91
|
+
# @example "iso8601"
|
92
|
+
# @return [String, nil]
|
93
|
+
attr_accessor :encoding
|
94
|
+
|
89
95
|
def initialize(cocina)
|
90
96
|
@cocina = cocina
|
91
97
|
@date = self.class.parse_date(cocina["value"])
|
92
98
|
@type = cocina["type"] unless ["start", "end"].include?(cocina["type"])
|
99
|
+
@encoding = cocina.dig("encoding", "code")
|
93
100
|
end
|
94
101
|
|
95
102
|
# Compare this date to another {Date} or {DateRange} using its {sort_key}.
|
@@ -115,14 +122,6 @@ module CocinaDisplay
|
|
115
122
|
qualifier.present?
|
116
123
|
end
|
117
124
|
|
118
|
-
# The encoding of this date, if specified.
|
119
|
-
# @example
|
120
|
-
# date.encoding #=> "iso8601"
|
121
|
-
# @return [String, nil]
|
122
|
-
def encoding
|
123
|
-
cocina.dig("encoding", "code")
|
124
|
-
end
|
125
|
-
|
126
125
|
# Was an encoding declared for this date?
|
127
126
|
# @return [Boolean]
|
128
127
|
def encoding?
|
@@ -515,6 +514,12 @@ module CocinaDisplay
|
|
515
514
|
end
|
516
515
|
end
|
517
516
|
|
517
|
+
# Extractor for dates that already match EDTF, they just didn't declare it
|
518
|
+
# Matches YYYY-MM-DD, YYYY-MM and YYYY; no further normalization needed
|
519
|
+
class UndeclaredEdtfFormat < ExtractorDateFormat
|
520
|
+
REGEX = /^(?<year>\d{4})(?:-(?<month>\d{2}))?(?:-(?<day>\d{2}))?$/
|
521
|
+
end
|
522
|
+
|
518
523
|
# Extractor for MM/DD/YYYY and MM/DD/YYY-formatted dates
|
519
524
|
class MMDDYYYYFormat < ExtractorDateFormat
|
520
525
|
REGEX = /(?<month>\d{1,2})\/(?<day>\d{1,2})\/(?<year>\d{3,4})/
|
@@ -13,7 +13,16 @@ module CocinaDisplay
|
|
13
13
|
def self.from_cocina(cocina)
|
14
14
|
return unless cocina["structuredValue"].present?
|
15
15
|
|
16
|
-
dates
|
16
|
+
# Create the individual dates; if no encoding/type declared give them
|
17
|
+
# top-level encoding/type
|
18
|
+
dates = cocina["structuredValue"].map do |sv|
|
19
|
+
date = Date.from_cocina(sv)
|
20
|
+
date.encoding ||= cocina.dig("encoding", "code")
|
21
|
+
date.type ||= cocina["type"]
|
22
|
+
date
|
23
|
+
end
|
24
|
+
|
25
|
+
# Ensure we have at least a start or a stop
|
17
26
|
start = dates.find(&:start?)
|
18
27
|
stop = dates.find(&:end?)
|
19
28
|
return unless start || stop
|
@@ -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
|
|