Skip to content

Commit

Permalink
Merge pull request #79 from mlibrary/electronic-collections-note-form…
Browse files Browse the repository at this point in the history
…atting

Electronic collections note formatting
  • Loading branch information
niquerio authored May 6, 2024
2 parents dc09b24 + 69838a9 commit d2b815f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,20 @@ 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,
collection_name,
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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down Expand Up @@ -121,41 +121,35 @@
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
it "returns expected hash values" do
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"
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d2b815f

Please sign in to comment.