neu-mods 0.1.0 → 0.1.1
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/.version +1 -1
- data/README.md +6 -0
- data/lib/neu/mods/projection.rb +14 -14
- data/lib/neu-mods.rb +5 -0
- 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: 4271827888541fa8ae2c61c52a6d3d73b79c7ee3ae3ae114ba391e3aae5e16a5
|
|
4
|
+
data.tar.gz: a59905f08b0092b40ade775cf95d846941d210b922aca213b5f1ee7b70ad864d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 25775e1c92de8bbc6f730980b1cbf78a5f0c78668ab901fb3c84f62e6ab15986bab6270ef37f511dfac367caa275d901b0cde87490a5b7d6f3338fd75d99415a
|
|
7
|
+
data.tar.gz: 61726ef704b127856f0fc1f2febe3b35681ffe48b7822a7cbbe1d30a4c8b094071bd681c57a1b3639c09f0ad1f085d4d3d543608fe86a7d2c558fa84ec913dc2
|
data/.version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.1.
|
|
1
|
+
0.1.1
|
data/README.md
CHANGED
|
@@ -34,6 +34,12 @@ doc.topical_subjects # => ["Civil society", ...] (every <topic>, for the acces
|
|
|
34
34
|
doc.keywords # => [...] (only the editable attribute-free keyword subjects)
|
|
35
35
|
doc.to_h # => full projection, keyed to Atlas's Metadata::MODS attributes
|
|
36
36
|
|
|
37
|
+
# Pure title composition (no document needed) — for callers that already hold
|
|
38
|
+
# the parts (e.g. Atlas's access-copy model) and must not re-parse XML on read.
|
|
39
|
+
NEU::MODS.compose_title(non_sort: "", title: "What's New",
|
|
40
|
+
part_name: "How We Respond to Disaster", part_number: "Episode 1")
|
|
41
|
+
# => "What's New - How We Respond to Disaster, Episode 1" (== doc.plain_title)
|
|
42
|
+
|
|
37
43
|
# Selectors (live nodes — for editing)
|
|
38
44
|
node = doc.primary_title_info.at_xpath("mods:title", NEU::MODS::NAMESPACE)
|
|
39
45
|
node.content = "New Title" unless NEU::MODS.whitespace_equivalent?(node.text, "New Title")
|
data/lib/neu/mods/projection.rb
CHANGED
|
@@ -31,13 +31,21 @@ module NEU
|
|
|
31
31
|
# Composed display title (the former Atlas MODSDecoration#plain_title), driven
|
|
32
32
|
# off the scoped primary title.
|
|
33
33
|
def plain_title
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
Projection.compose_title(title_parts)
|
|
35
|
+
end
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
# Pure title composition over a parts hash, factored out of #plain_title so
|
|
38
|
+
# callers that already hold the parts -- e.g. Atlas's access-copy model --
|
|
39
|
+
# can compose the display title WITHOUT re-parsing XML on the read path
|
|
40
|
+
# (reaching for Nokogiri in a decorator is the smell this avoids). Keys:
|
|
41
|
+
# :non_sort :title :subtitle :part_name :part_number (nil or "" for absent).
|
|
42
|
+
# Returns "" when there is no title. Exposed as NEU::MODS.compose_title.
|
|
43
|
+
def self.compose_title(parts)
|
|
44
|
+
return "" if parts[:title].to_s.strip.empty?
|
|
45
|
+
|
|
46
|
+
optional = { ": " => parts[:subtitle], " - " => parts[:part_name], ", " => parts[:part_number] }
|
|
47
|
+
suffix = optional.filter_map { |sep, val| "#{sep}#{val}" unless val.to_s.strip.empty? }.join
|
|
48
|
+
"#{parts[:non_sort]}#{parts[:title]}#{suffix}"
|
|
41
49
|
end
|
|
42
50
|
|
|
43
51
|
# --- Abstract / access ---------------------------------------------------
|
|
@@ -176,14 +184,6 @@ module NEU
|
|
|
176
184
|
v.empty? ? nil : v
|
|
177
185
|
end
|
|
178
186
|
|
|
179
|
-
def blank?(str)
|
|
180
|
-
str.nil? || str.strip.empty?
|
|
181
|
-
end
|
|
182
|
-
|
|
183
|
-
def prefix(sep, val)
|
|
184
|
-
blank?(val) ? "" : "#{sep}#{val}"
|
|
185
|
-
end
|
|
186
|
-
|
|
187
187
|
def join_paragraphs(nodes)
|
|
188
188
|
nodes.map { |n| NEU::MODS.normalize_paragraphs(n.text) }.reject(&:empty?).join("\n\n")
|
|
189
189
|
end
|
data/lib/neu-mods.rb
CHANGED
|
@@ -33,5 +33,10 @@ module NEU
|
|
|
33
33
|
# Curator-freetext normalization for the access copy (see TextNormalizer).
|
|
34
34
|
def normalize(str) = TextNormalizer.normalize(str)
|
|
35
35
|
def normalize_paragraphs(str) = TextNormalizer.normalize_paragraphs(str)
|
|
36
|
+
|
|
37
|
+
# Pure display-title composition over a primary-title parts hash (see
|
|
38
|
+
# Projection.compose_title). Lets a caller that already holds the parts --
|
|
39
|
+
# e.g. Atlas's access-copy model -- compose the title without parsing XML.
|
|
40
|
+
def compose_title(parts) = Projection.compose_title(parts)
|
|
36
41
|
end
|
|
37
42
|
end
|