cocina_display 1.1.1 → 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/dates/date.rb +13 -8
- data/lib/cocina_display/dates/date_range.rb +10 -1
- 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
|
@@ -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
|