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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e2b164eda474dc396b74c8b911fe50bbba7c2dbbce17b29c24923db4f25ff8a5
4
- data.tar.gz: c782186b53a4dcb7f53b11a3d552dcf5f892f4435fc46fb4bcddd65ad444d9be
3
+ metadata.gz: b6eddb643cc7413aaefd5b2b73df29c7d9aaa98ce7a0008816d405c82f73517d
4
+ data.tar.gz: 0ce368a036754577ab65e1f917750f4b6142d48bcb413eb202a4538324fca2ea
5
5
  SHA512:
6
- metadata.gz: efed0c780617aaeadb7187391c74691bcacddcb24cb2850e14918ab755acfaef273c8e3277a9c4674b2b41201a72ffe91a79a0065daa07ad469e2178ea17fd92
7
- data.tar.gz: 28933bab6be3f6cd2fed4155d5b4a73bf9f9d9301e5edc679018f6428d90f88ca14ab8a6614d1c07e53f1723644b0871786fb075b664bb7e2fb73dba96d21588
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 = cocina["structuredValue"].map { |sv| Date.from_cocina(sv) }
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
@@ -2,5 +2,5 @@
2
2
 
3
3
  # :nodoc:
4
4
  module CocinaDisplay
5
- VERSION = "1.1.1" # :nodoc:
5
+ VERSION = "1.1.2" # :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.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Budak