diff --git a/umich_catalog_indexing/lib/jobs/translation_map_generator/electronic_collections.rb b/umich_catalog_indexing/lib/jobs/translation_map_generator/electronic_collections.rb index fa01704d..e6724d72 100644 --- a/umich_catalog_indexing/lib/jobs/translation_map_generator/electronic_collections.rb +++ b/umich_catalog_indexing/lib/jobs/translation_map_generator/electronic_collections.rb @@ -97,16 +97,20 @@ def interface_name preferred_value("Electronic Collection Interface Name") end - # Returns the appropriate note. Authentication Note is the highest - # priority. Interface Name is the least priority. Returns nil if - # everything is nil + # Concatentates interface name, public note, and authentication note. + # Also strips out any trailing punctuation except closing parens and + # square brackets. The rest are terminated with a period. def note [ - @data["Electronic Collection Authentication Note"], + interface_name, @data["Electronic Collection Public Note"], - collection_name, - interface_name - ].find { |x| x } + @data["Electronic Collection Authentication Note"] + ].compact.map do |x| + out = x.strip + .sub(/[[\p{P}]&&[^\])]]$/, "") + out.sub!(/$/, ".") if out.match?(/[^\])]$/) + out + end.join(" ") end # Returns a hash summary of the collection metadata. This becomes a row in diff --git a/umich_catalog_indexing/lib/umich_traject/electronic_holding.rb b/umich_catalog_indexing/lib/umich_traject/electronic_holding.rb index 6cd8335f..37d5cac0 100644 --- a/umich_catalog_indexing/lib/umich_traject/electronic_holding.rb +++ b/umich_catalog_indexing/lib/umich_traject/electronic_holding.rb @@ -59,6 +59,9 @@ def public_note @e56["z"] end + # Concatentates interface name, collection name, authentication note, and + # public note. Also strips out any trailing punctuation except closing + # parens and square brackets. The rest are terminated with a period. def note [ interface_name, @@ -66,7 +69,10 @@ def note authentication_note, public_note ].flatten.compact.map do |x| - x.strip.sub(/\p{P}$/, "").sub(/$/, ".") + out = x.strip + .sub(/[[\p{P}]&&[^\])]]$/, "") + out.sub!(/$/, ".") if out.match?(/[^\])]$/) + out end.join(" ") end diff --git a/umich_catalog_indexing/spec/jobs/translation_map_generator/electronic_collections_spec.rb b/umich_catalog_indexing/spec/jobs/translation_map_generator/electronic_collections_spec.rb index d0db538c..06035b65 100644 --- a/umich_catalog_indexing/spec/jobs/translation_map_generator/electronic_collections_spec.rb +++ b/umich_catalog_indexing/spec/jobs/translation_map_generator/electronic_collections_spec.rb @@ -26,7 +26,7 @@ { "collection_name" => "OVERRIDE_NAME", "interface_name" => "OVERRIDE_INTERFACE", - "note" => "AUTH_NOTE", + "note" => "OVERRIDE_INTERFACE. PUBLIC_NOTE. AUTH_NOTE.", "link" => "OVERRIDE_URL", "status" => "Available" } @@ -121,33 +121,27 @@ end end context "#note" do - it "returns the Authentication note if it exists" do - expect(subject.note).to eq("AUTH_NOTE") + it "returns the Interface name. Public Note. Authentication Note. when they all exist" do + s = subject + expect(s.note).to eq("#{s.interface_name}. PUBLIC_NOTE. AUTH_NOTE.") end - it "returns the Public Note when there's no auth note and it exists" do + it "returns handles empty options" do @item["Electronic Collection Authentication Note"] = nil - expect(subject.note).to eq("PUBLIC_NOTE") + s = subject + expect(s.note).to eq("#{s.interface_name}. PUBLIC_NOTE.") end - it "returns the collection_name if there's no auth note and no public note" do + it "returns empty string if there's no note and no collection name and no interface name" do @item["Electronic Collection Authentication Note"] = nil @item["Electronic Collection Public Note"] = nil - expect(subject.note).to eq("OVERRIDE_NAME") - end - it "returns the interface name if there's no auth note or public note or collection name" do - @item["Electronic Collection Authentication Note"] = nil - @item["Electronic Collection Public Note"] = nil - @item["Electronic Collection Public Name (override)"] = nil - @item["Electronic Collection Public Name"] = nil - expect(subject.note).to eq("OVERRIDE_INTERFACE") - end - it "returns nil if there's no note and no collection name and no interface name" do - @item["Electronic Collection Authentication Note"] = nil - @item["Electronic Collection Public Note"] = nil - @item["Electronic Collection Public Name (override)"] = nil - @item["Electronic Collection Public Name"] = nil @item["Electronic Collection Interface Name (override)"] = nil @item["Electronic Collection Interface Name"] = nil - expect(subject.note).to eq(nil) + expect(subject.note).to eq("") + end + it "gets replaces non period punctuation with periods. It leaves closing parens and square brackets" do + @item["Electronic Collection Interface Name (override)"] = "INTERFACE_NAME;" + @item["Electronic Collection Public Note"] = "(PUBLIC_NOTE)" + @item["Electronic Collection Authentication Note"] = "[AUTH_NOTE]" + expect(subject.note).to eq("INTERFACE_NAME. (PUBLIC_NOTE) [AUTH_NOTE]") end end context "#to_h" do @@ -155,7 +149,7 @@ expect(subject.to_h).to eq({ "collection_name" => "OVERRIDE_NAME", "interface_name" => "OVERRIDE_INTERFACE", - "note" => "AUTH_NOTE", + "note" => "OVERRIDE_INTERFACE. PUBLIC_NOTE. AUTH_NOTE.", "link" => "OVERRIDE_URL", "status" => "Available" }) diff --git a/umich_catalog_indexing/spec/traject/umich/electronic_holding_spec.rb b/umich_catalog_indexing/spec/traject/umich/electronic_holding_spec.rb index 2fcb693f..5993ee53 100644 --- a/umich_catalog_indexing/spec/traject/umich/electronic_holding_spec.rb +++ b/umich_catalog_indexing/spec/traject/umich/electronic_holding_spec.rb @@ -113,6 +113,12 @@ def get_record(path) it "shows combined note" do expect(subject.note).to eq("Elsevier ScienceDirect. Elsevier SD eBook - Physics and Astronomy. Access to the Elsevier ScienceDirect eBook - Physics and Astronomy (Legacy 1) online version restricted; authentication may be required. Elsevier ScienceDirect access restricted; authentication may be required. Public note.") end + it "handles concatenates with periods unless theres a ] or ) ending" do + @e56.subfields.find { |x| x.code == "z" }.value = "(Parens)" + @e56.subfields.find { |x| x.code == "4" }.value = "[Square]" + @e56.subfields.find { |x| x.code == "n" }.value = "Ends in semicolon;" + expect(subject.note).to eq("Elsevier ScienceDirect. Ends in semicolon. [Square] Elsevier ScienceDirect access restricted; authentication may be required. (Parens)") + end end context "#status" do it "shows the status in subfield s" do