cocina_display 1.12.1 → 1.12.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/note.rb +28 -9
- data/lib/cocina_display/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2310483e28449dd22935fae9e5e19097c69d133cf0e393f45a5a2d9f6b0d2182
|
|
4
|
+
data.tar.gz: e63dd927ad075874c6f8b1b5ba5344be97d6bb659ebde892f7fd05220f874c7e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c9e72b785cdef2be3ff32d5b2ae06863a0385d9c48f70c888c9296bf8ecee6b1762cd155b8eb1ca2cbed2ada8ec6867ee7b7675de37be24c3ca823a3fbc6924b
|
|
7
|
+
data.tar.gz: 0bfde5b69633b904e244be9728d225672a80392702878972a981c2c857201cf1a3940256b4c015bc6a97bd04abb0b2241bf2e8c3284ddd29d35565aec09249fc
|
data/lib/cocina_display/note.rb
CHANGED
|
@@ -8,14 +8,12 @@ module CocinaDisplay
|
|
|
8
8
|
TOC_TYPES = ["table of contents"].freeze
|
|
9
9
|
TOC_DISPLAY_LABEL_REGEX = /Table of contents/i
|
|
10
10
|
|
|
11
|
-
attr_reader :cocina
|
|
11
|
+
attr_reader :cocina
|
|
12
12
|
|
|
13
13
|
# Initialize a Note from Cocina structured data.
|
|
14
14
|
# @param cocina [Hash]
|
|
15
|
-
|
|
16
|
-
def initialize(cocina, delimiter: " -- ")
|
|
15
|
+
def initialize(cocina)
|
|
17
16
|
@cocina = cocina
|
|
18
|
-
@delimiter = delimiter
|
|
19
17
|
end
|
|
20
18
|
|
|
21
19
|
# The value to use for display.
|
|
@@ -24,28 +22,47 @@ module CocinaDisplay
|
|
|
24
22
|
flat_value
|
|
25
23
|
end
|
|
26
24
|
|
|
25
|
+
# Delimiter used to join multiple values for display.
|
|
26
|
+
# @return [String, nil]
|
|
27
|
+
def delimiter
|
|
28
|
+
" -- " if table_of_contents?
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Does this note use a delimiter?
|
|
32
|
+
# @return [Boolean]
|
|
33
|
+
def delimited?
|
|
34
|
+
delimiter.present?
|
|
35
|
+
end
|
|
36
|
+
|
|
27
37
|
# Single concatenated string value for the note.
|
|
28
38
|
# @return [String, nil]
|
|
29
39
|
def flat_value
|
|
30
|
-
Utils.compact_and_join(values, delimiter: delimiter).presence
|
|
40
|
+
Utils.compact_and_join(values, delimiter: delimiter || "").presence
|
|
31
41
|
end
|
|
32
42
|
|
|
33
43
|
# The raw values from the Cocina data, flattened if nested.
|
|
34
44
|
# Strips excess whitespace and the delimiter if present.
|
|
45
|
+
# Splits on the delimiter if it was already included in the values(s).
|
|
35
46
|
# @return [Array<String>]
|
|
36
47
|
def values
|
|
37
48
|
Utils.flatten_nested_values(cocina).pluck("value")
|
|
38
49
|
.map { |value| cleaned_value(value) }
|
|
50
|
+
.flat_map { |value| delimited? ? value.split(delimiter.strip) : [value] }
|
|
39
51
|
.compact_blank
|
|
40
52
|
end
|
|
41
53
|
|
|
42
54
|
# The raw values from the Cocina data as a hash with type as key.
|
|
43
|
-
#
|
|
55
|
+
# Strips excess whitespace and the delimiter if present.
|
|
56
|
+
# Splits on the delimiter if it was already included in the values(s).
|
|
57
|
+
# @return [Hash{String => Array<String>}]
|
|
44
58
|
def values_by_type
|
|
45
59
|
Utils.flatten_nested_values(cocina).each_with_object({}) do |node, hash|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
60
|
+
value = cleaned_value(node["value"])
|
|
61
|
+
(delimited? ? value.split(delimiter.strip) : [value]).each do |part|
|
|
62
|
+
type = node["type"]
|
|
63
|
+
hash[type] ||= []
|
|
64
|
+
hash[type] << part
|
|
65
|
+
end
|
|
49
66
|
end
|
|
50
67
|
end
|
|
51
68
|
|
|
@@ -115,6 +132,8 @@ module CocinaDisplay
|
|
|
115
132
|
# @param value [String]
|
|
116
133
|
# @return [String]
|
|
117
134
|
def cleaned_value(value)
|
|
135
|
+
return value.strip unless delimited?
|
|
136
|
+
|
|
118
137
|
value.gsub(/\s*#{Regexp.escape(delimiter.strip)}\s*$/, " ")
|
|
119
138
|
.gsub(/^\s*#{Regexp.escape(delimiter.strip)}\s*/, " ")
|
|
120
139
|
.strip
|
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.12.
|
|
4
|
+
version: 1.12.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Nick Budak
|
|
8
8
|
bindir: exe
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date: 2026-03-
|
|
10
|
+
date: 2026-03-06 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: janeway-jsonpath
|