From 2f42d9130ace628e016fbadcf09418bbf4069305 Mon Sep 17 00:00:00 2001 From: Banu Hapeloglu Kutlu Date: Tue, 4 Aug 2020 17:12:33 -0400 Subject: [PATCH] Need to strip oclc leading zeros for hathi data lookup (#229) --- .rubocop_todo.yml | 2 +- lib/traject/macros/custom.rb | 2 +- spec/lib/traject/macros/custom_spec.rb | 8 ++++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 2f0938ff..39caed46 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -15,7 +15,7 @@ Metrics/AbcSize: # Configuration parameters: CountComments, ExcludedMethods. # ExcludedMethods: refine Metrics/BlockLength: - Max: 212 + Max: 218 # Offense count: 2 # Configuration parameters: CountComments. diff --git a/lib/traject/macros/custom.rb b/lib/traject/macros/custom.rb index 3ea44b07..567195e9 100644 --- a/lib/traject/macros/custom.rb +++ b/lib/traject/macros/custom.rb @@ -207,7 +207,7 @@ def self.includes_oclc_indicators?(sf_a) def extract_hathi_data lambda do |_record, accumulator, context| - oclc_number = context.output_hash&.dig('oclc_number_ssim')&.first + oclc_number = context.output_hash&.dig('oclc_number_ssim')&.first.to_i.to_s ht_hash = HATHI_MULTI_OVERLAP&.dig(oclc_number)&.first || HATHI_MONO_OVERLAP&.dig(oclc_number)&.first accumulator << ht_hash.to_json unless ht_hash.nil? end diff --git a/spec/lib/traject/macros/custom_spec.rb b/spec/lib/traject/macros/custom_spec.rb index 293d562d..7f0b62b1 100644 --- a/spec/lib/traject/macros/custom_spec.rb +++ b/spec/lib/traject/macros/custom_spec.rb @@ -218,6 +218,14 @@ expect(result['hathitrust_struct']).to match ['{"ht_bib_key":"012292266","access":"allow"}'] end end + + context 'when a record has an oclc with leading zeros' do + let(:oclc) { { '035' => { 'ind1' => '', 'ind2' => '', 'subfields' => [{ 'a' => '(OCLC)00100000391' }] } } } + + it 'finds a match after stripping the leading zeros' do + expect(result['hathitrust_struct']).to match ['{"ht_bib_key":"012292266","access":"allow"}'] + end + end end describe '#hathi_to_hash' do