Skip to content

Commit

Permalink
Add Bulk Checker module to Detector::Journal
Browse files Browse the repository at this point in the history
** Why are these changes being introduced:

Now that the Detector::Journal model is only concerns with detections,
and calling Detector::Journal.new no longer spawns any database records,
we can implement the BulkChecker module for better developer experience.

** Relevant ticket(s):

* https://mitlibraries.atlassian.net/browse/tco-110

** How does this address that need:

This defines a @Detections attribute on the Detector::Journal class,
as well as an initialize method to populate that attribute based on the
full_term_match method.

This allows the BulkChecker-provided .check_all_matches method to return
meaningful information.

** Document any side effects to this change:

This implementation may be too minimal, as the initialize method ends
up calling the singleton methods in a slightly awkward way (or maybe I
need to get used to this way of working, and not expect to just call
full_term_matches directly in the initializer).
  • Loading branch information
matt-bernhardt committed Dec 19, 2024
1 parent dd30001 commit 5f99223
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
9 changes: 9 additions & 0 deletions app/models/detector/journal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ class Detector
# Detector::Journal stores information about academic journals loaded from external sources to allow us to check our
# incoming Terms against these information
class Journal
attr_reader :detections

# shared singleton methods
extend Detector::BulkChecker

def initialize(phrase)
@detections = Detector::Journal.full_term_match(phrase)
end

# Identify journals in which the incoming phrase matches a Journal.name exactly
#
# @note We always store the Journal.name downcased, so we should also always downcase the phrase
Expand Down
4 changes: 3 additions & 1 deletion test/models/detector/bulk_checker_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ class CitationTest < ActiveSupport::TestCase
end

test 'journal_bulk_checker' do
skip 'Detector::Journal does not yet support bulk_checker'
bulk = Detector::Journal.check_all_matches(output: true)

assert_equal(1, bulk.count)
end

test 'lcsh_bulk_checker' do
Expand Down

0 comments on commit 5f99223

Please sign in to comment.