Skip to content

Commit

Permalink
Minor changes to DOI checker code
Browse files Browse the repository at this point in the history
  • Loading branch information
xuanxu committed Aug 20, 2024
1 parent 42fcd98 commit 6c373ce
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
6 changes: 2 additions & 4 deletions app/lib/doi_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ def check_dois
if @entries.any?
@entries.each do |entry|
# handle special cases first
special_case = self.handle_special_case(entry)
if special_case
if special_case = handle_special_case(entry)
doi_validity = special_case
elsif entry.has_field?('doi') && !entry.doi.empty?
# Validate entries with DOIs
Expand All @@ -38,8 +37,7 @@ def check_dois
# {:validity => :ok, :msg => "whatever"} otherwise.
# Add additional special cases as private methods and chain in a tidy sequence plz <3
def handle_special_case(entry)
validity = acm_105555_prefix(entry) and return validity
false
acm_105555_prefix(entry) || false
end


Expand Down
10 changes: 5 additions & 5 deletions app/responses/doi_checks.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
Reference check summary (note 'MISSING' DOIs are suggestions that need verification):
<% doi_summary.each do |type, messages| -%>
<% if type.to_s === "ok" %>
- <%= type.to_s.upcase %> DOIs
<%= type.to_s.upcase %> DOIs
<% elsif type.to_s === "skip" %>
- <%= type.to_s.upcase %> DOIs
<%= type.to_s.upcase %> DOIs
<% else %>
- <%= type.to_s.upcase %> DOIs
<%= type.to_s.upcase %> DOIs
<% end %>
<% if messages.empty? -%>
- None
<% else -%>
<% messages.each do |message| -%>
- <%= message%>
<% messages.each do |message| -%>
- <%= message %>
<% end -%>
<% end -%>
<% end -%>
Expand Down
9 changes: 9 additions & 0 deletions spec/doi_checker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
expect(doi_summary[:ok]).to be_empty
expect(doi_summary[:invalid]).to be_empty
expect(doi_summary[:missing]).to be_empty
expect(doi_summary[:skip]).to be_empty
end

it "should classify as invalid entries with invalid DOI" do
Expand All @@ -25,6 +26,7 @@
expect(doi_summary[:invalid].size).to eq(1)
expect(doi_summary[:invalid].first).to eq(validity[:msg])
expect(doi_summary[:missing]).to be_empty
expect(doi_summary[:skip]).to be_empty
end

it "should classify as ok entries with valid DOI" do
Expand All @@ -39,6 +41,7 @@
expect(doi_summary[:ok].first).to eq(validity[:msg])
expect(doi_summary[:invalid]).to be_empty
expect(doi_summary[:missing]).to be_empty
expect(doi_summary[:skip]).to be_empty
end

it "should classify as missing entries without DOI but with a candidate crossref entry" do
Expand All @@ -50,6 +53,7 @@
doi_summary = doi_checker.check_dois
expect(doi_summary[:ok]).to be_empty
expect(doi_summary[:invalid]).to be_empty
expect(doi_summary[:skip]).to be_empty
expect(doi_summary[:missing].size).to eq(1)
expect(doi_summary[:missing][0]).to eq("10.maybe/doi may be a valid DOI for title: No DOI")
end
Expand All @@ -63,6 +67,7 @@
doi_summary = doi_checker.check_dois
expect(doi_summary[:ok]).to be_empty
expect(doi_summary[:invalid]).to be_empty
expect(doi_summary[:skip]).to be_empty
expect(doi_summary[:missing].size).to eq(1)
expect(doi_summary[:missing][0]).to eq('Errored finding suggestions for "No DOI", please try later')
end
Expand All @@ -78,6 +83,7 @@
doi_summary = doi_checker.check_dois
expect(doi_summary[:ok]).to be_empty
expect(doi_summary[:invalid]).to be_empty
expect(doi_summary[:skip]).to be_empty
expect(doi_summary[:missing].size).to eq(1)
expect(doi_summary[:missing][0]).to eq("Errored finding suggestions for \"#{expected_title}\", please try later")
end
Expand All @@ -93,6 +99,8 @@

expect(doi_summary[:ok]).to be_empty
expect(doi_summary[:invalid]).to be_empty
expect(doi_summary[:missing]).to be_empty
expect(doi_summary[:skip].size).to eq(1)
expect(doi_summary[:skip][0]).to eq("No DOI given, and none found for title: #{title}")
end

Expand All @@ -103,6 +111,7 @@
doi_summary = doi_checker.check_dois
expect(doi_summary[:ok]).to be_empty
expect(doi_summary[:invalid]).to be_empty
expect(doi_summary[:skip]).to be_empty
expect(doi_summary[:missing][0]).to eq("Entry without DOI or title found")
end
end
Expand Down

0 comments on commit 6c373ce

Please sign in to comment.