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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ab1cb07bf4122e98017ded99c790824865f68fb8ccdfdcbb3b5fc8e7d72cbf55
4
- data.tar.gz: 6d3b467da6fde096e0ea26f9e76c447ea24c563c6cc5fd1a47e06b8f18d72aca
3
+ metadata.gz: 4271827888541fa8ae2c61c52a6d3d73b79c7ee3ae3ae114ba391e3aae5e16a5
4
+ data.tar.gz: a59905f08b0092b40ade775cf95d846941d210b922aca213b5f1ee7b70ad864d
5
5
  SHA512:
6
- metadata.gz: 4c9b5a6006cf0ab3faced2d60f49f703ab482f28f2208d39c5225bd7af769c4f6bba634b0808d83d3b5ac3f2210efca07f8b1ad37976e0ed17d1175d666fcccf
7
- data.tar.gz: 2c92060d9faddce439bb9b462982fbb186f6d792f5fc86cfa9702a7cf1c2118c06a3236a5e0875c2499e5593083f531a5668c841696168d330c6527728ca56a7
6
+ metadata.gz: 25775e1c92de8bbc6f730980b1cbf78a5f0c78668ab901fb3c84f62e6ab15986bab6270ef37f511dfac367caa275d901b0cde87490a5b7d6f3338fd75d99415a
7
+ data.tar.gz: 61726ef704b127856f0fc1f2febe3b35681ffe48b7822a7cbbe1d30a4c8b094071bd681c57a1b3639c09f0ad1f085d4d3d543608fe86a7d2c558fa84ec913dc2
data/.version CHANGED
@@ -1 +1 @@
1
- 0.1.0
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")
@@ -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
- p = title_parts
35
- return "" if blank?(p[:title])
34
+ Projection.compose_title(title_parts)
35
+ end
36
36
 
37
- "#{p[:non_sort]}#{p[:title]}" +
38
- prefix(": ", p[:subtitle]) +
39
- prefix(" - ", p[:part_name]) +
40
- prefix(", ", p[:part_number])
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: neu-mods
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Cliff