11# frozen_string_literal: true
22
3- # == Schema Information
4- #
5- # Table name: detector_journals
6- #
7- # id :integer not null, primary key
8- # name :string
9- # additional_info :json
10- # created_at :datetime not null
11- # updated_at :datetime not null
12- #
133class Detector
14- # Detector::Journal stores information about academic journals loaded from external sources to allow us to check our
15- # incoming Terms against these information
16- class Journal < ApplicationRecord
17- before_save :downcase_fields!
4+ # Detector::Journal handles the comparison between incoming Term records and our known list of academic journals
5+ # (which are managed by the separate Journal model).
6+ class Journal
7+ attr_reader :detections
188
19- def self . table_name_prefix
20- 'detector_'
9+ # shared singleton methods
10+ extend Detector ::BulkChecker
11+
12+ def initialize ( phrase )
13+ @detections = Detector ::Journal . full_term_match ( phrase )
2114 end
2215
2316 # Identify journals in which the incoming phrase matches a Journal.name exactly
@@ -30,9 +23,9 @@ def self.table_name_prefix
3023 #
3124 # @param phrase [String]. A string representation of a search term (not an actual Term object!)
3225 #
33- # @return [Set of Detector:: Journal] A set of ActiveRecord Detector:: Journal relations .
26+ # @return [Set of Journal] A set of ActiveRecord Journal records .
3427 def self . full_term_match ( phrase )
35- Journal . where ( name : phrase . downcase )
28+ :: Journal . where ( name : phrase . downcase )
3629 end
3730
3831 # Identify journals in which the incoming phrase contains one or more Journal names
@@ -41,12 +34,12 @@ def self.full_term_match(phrase)
4134 #
4235 # @param phrase [String]. A string representation of a search term (not an actual Term object!)
4336 #
44- # @return [Set of Detector:: Journal] A set of ActiveRecord Detector:: Journal relations .
37+ # @return [Set of Journal] A set of ActiveRecord Journal records .
4538 def self . partial_term_match ( phrase )
46- Journal . all . select { |journal | phrase . downcase . include? ( journal . name ) }
39+ :: Journal . all . select { |journal | phrase . downcase . include? ( journal . name ) }
4740 end
4841
49- # Look up any matching Detector:: Journal records, building on the full_term_match method. If a match is found, a
42+ # Look up any matching Journal records, building on the full_term_match method. If a match is found, a
5043 # Detection record is created to indicate this success.
5144 #
5245 # @note This does not care whether multiple matching journals are detected. If _any_ match is found, a Detection
@@ -65,13 +58,5 @@ def self.record(term)
6558
6659 nil
6760 end
68-
69- private
70-
71- # Downcasing all names before saving allows for more efficient matching by ensuring our index is lowercase.
72- # If we find we need the non-lowercase Journal name in the future, we could store that as `additional_info` json
73- def downcase_fields!
74- name . downcase!
75- end
7661 end
7762end
0 commit comments