Skip to content

Commit

Permalink
Changes availability output to 5 states
Browse files Browse the repository at this point in the history
  • Loading branch information
niquerio committed Jun 27, 2024
1 parent 81c94e8 commit 5f3ba8c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
11 changes: 10 additions & 1 deletion umich_catalog_indexing/lib/umich_traject/availability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ def electronic_holding?
@hol.select { |x| ALMA_ELECTRONIC_LIBRARIES.any?(x["library"]) }.any?
end

def hathi_trust_or_electronic_holding?
hathi_trust? || electronic_holding?
end

def hathi_trust_full_text_or_electronic_holding?
hathi_trust_full_text? || electronic_holding?
end

# Returns an array of availabilies for the holding structure. This is the
# method that's called by the application.
# @return [Array<String>]
Expand All @@ -47,7 +55,8 @@ def to_a
"physical",
"hathi_trust",
"hathi_trust_full_text",
"electronic_holding"
"hathi_trust_or_electronic_holding",
"hathi_trust_full_text_or_electronic_holding"
].select { |x| send(:"#{x}?") }
end

Expand Down
30 changes: 29 additions & 1 deletion umich_catalog_indexing/spec/traject/umich/availability_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,38 @@
end
end

context "hathi_trust_or_electronic_holding?" do
it "returns true when hathitrust item" do
expect(subject.hathi_trust_or_electronic_holding?).to eq(true)
end
it "returns true when there's an electronic holding" do
@hol[1]["library"] = "ELEC"
expect(subject.hathi_trust_or_electronic_holding?).to eq(true)
end
it "returns false when there's no electronic or HT record" do
@hol.delete_at(1)
expect(subject.hathi_trust_or_electronic_holding?).to eq(false)
end
end

context "hathi_trust_full_text_or_electronic_holding?" do
it "returns false when neither ht full text or electronic holding" do
expect(subject.hathi_trust_full_text_or_electronic_holding?).to eq(false)
end
it "returns true when hathitrust full text" do
@hol[1]["items"].push({"rights" => "pd"})
expect(subject.hathi_trust_full_text_or_electronic_holding?).to eq(true)
end
it "returns true when there's an electronic holding" do
@hol[1]["library"] = "ELEC"
expect(subject.hathi_trust_full_text_or_electronic_holding?).to eq(true)
end
end

context "#to_a" do
it "returns an array of availability values" do
expect(subject.to_a).to contain_exactly(
"physical", "hathi_trust"
"physical", "hathi_trust", "hathi_trust_or_electronic_holding"
)
end
end
Expand Down

0 comments on commit 5f3ba8c

Please sign in to comment.