Skip to content

Commit

Permalink
Merge pull request #732 from pulibrary/i703_make_pub_location_configu…
Browse files Browse the repository at this point in the history
…rable

Make excluding US / UK / Canada pub locations configurable
  • Loading branch information
kevinreiss authored Mar 26, 2024
2 parents f36ba72 + b687e4d commit 5480c70
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 4 deletions.
10 changes: 8 additions & 2 deletions app/models/oclc/lc_call_slips/record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,17 @@ def initialize(marc_record:)
end

def generally_relevant?
!juvenile? && !audiobook? && !published_in_us_uk_or_canada? && monograph? && within_last_two_years?
!juvenile? && !audiobook? && monograph? && within_last_two_years?
end

def relevant_to_selector?(selector:)
call_number_in_range_for_selector?(selector:) || subject_relevant_to_selector?(selector:)
location_relevant_to_selector?(selector:) && (call_number_in_range_for_selector?(selector:) || subject_relevant_to_selector?(selector:))
end

def location_relevant_to_selector?(selector:)
return true if selector.include_us_uk_canada?

!published_in_us_uk_or_canada?
end

def call_number_in_range_for_selector?(selector:)
Expand Down
6 changes: 6 additions & 0 deletions app/models/oclc/lc_call_slips/selector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ def subjects
selector_config[selector_key][:subjects]
end

def include_us_uk_canada?
return false unless selector_config[selector_key].keys.include?(:include_us_uk_canada)

selector_config[selector_key][:include_us_uk_canada]
end

def selector_key
selector_config.keys.first
end
Expand Down
1 change: 1 addition & 0 deletions config/lc_call_slips.yml
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ default: &default
- Cairo Geniza
- Rabbinical
- Talmud
include_us_uk_canada: true
- painter:
email: [email protected]
classes:
Expand Down
2 changes: 1 addition & 1 deletion spec/models/oclc/lc_call_slips/all_relevant_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
subject.run
expect(File.exist?(new_csv_path)).to be true
csv_file = CSV.read(new_csv_path)
expect(csv_file.length).to eq(529)
expect(csv_file.length).to eq(1152)
end
end
40 changes: 39 additions & 1 deletion spec/models/oclc/lc_call_slips/record_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
let(:marc_record) { MARC::Record.new_from_hash('fields' => fields) }
let(:fields) do
[
{ '008' => '120627s2024 ncuabg ob 001 0 gre d' },
{ '650' => { "ind1" => "",
"ind2" => "0",
'subfields' => [
Expand Down Expand Up @@ -60,6 +61,7 @@
end
let(:fields) do
[
{ '008' => '120627s2024 gerabg ob 001 0 gre d' },
{ '650' => { "ind1" => "",
"ind2" => "0",
'subfields' => [
Expand Down Expand Up @@ -225,7 +227,7 @@
end

it 'can tell if a record is relevant to the selector' do
expect(oclc_record.relevant_to_selector?(selector:)).to be true
expect(oclc_record.relevant_to_selector?(selector:)).to be false
end

it 'can tell if a class is relevant to the selector' do
Expand Down Expand Up @@ -369,4 +371,40 @@
end
end
end

context 'a selector who wants US, UK, and Canada publications' do
let(:selector_config) do
{ hollander: {
classes: [{ class: 'G', low_num: 154.9, high_num: 155.8 },
{ class: 'HD', low_num: 0, high_num: 99_999 }],
subjects: ['Judaism'],
include_us_uk_canada: true
} }
end
let(:marc_record) { MARC::Record.new_from_hash('fields' => fields, 'leader' => leader) }
let(:fields) do
[
{ '008' => '120627s2024 ncuabg ob 001 0 gre d' },
{ '650' => { "ind1" => "",
"ind2" => "0",
'subfields' => [
{ 'a' => 'Judaism' }
] } }
]
end
let(:leader) { '00852cam a2200277 i 4500' }
it 'recognizes that the record is relevant to the selector' do
expect(oclc_record.published_in_us_uk_or_canada?).to eq(true)
expect(oclc_record.subject_relevant_to_selector?(selector:)).to eq(true)
expect(oclc_record.location_relevant_to_selector?(selector:)).to eq(true)
expect(oclc_record.relevant_to_selector?(selector:)).to eq(true)
end
it 'recognizes that the record is generally relevant' do
expect(oclc_record.monograph?).to eq(true)
expect(oclc_record.within_last_two_years?).to eq(true)
expect(oclc_record.juvenile?).to eq(false)
expect(oclc_record.audiobook?).to eq(false)
expect(oclc_record.generally_relevant?).to eq(true)
end
end
end
23 changes: 23 additions & 0 deletions spec/models/oclc/lc_call_slips/selector_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,27 @@
it 'has an array of subjects' do
expect(second_selector.subjects).to match_array(['foreign relations', 'politic', 'policy', 'government'])
end

describe '#include_us_uk_canada?' do
context 'a selector who wants US, UK, and Canada publications' do
let(:selector_config) do
{ hollander: {
classes: [{ class: 'G', low_num: 154.9, high_num: 155.8 },
{ class: 'HD', low_num: 0, high_num: 99_999 }],
subjects: ['economic aspects'],
include_us_uk_canada: true
} }
end
let(:selector) { described_class.new(selector_config:) }

it 'returns true' do
expect(selector.include_us_uk_canada?).to eq(true)
end
end
context 'a selector who defaults to not wanting US, UK, and Canada publications' do
it 'returns false' do
expect(first_selector.include_us_uk_canada?).to eq(false)
end
end
end
end

0 comments on commit 5480c70

Please sign in to comment.