Skip to content

Commit

Permalink
Need to strip oclc leading zeros for hathi data lookup (#229)
Browse files Browse the repository at this point in the history
  • Loading branch information
Banu Hapeloglu Kutlu authored Aug 4, 2020
1 parent a77b705 commit 2f42d91
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Metrics/AbcSize:
# Configuration parameters: CountComments, ExcludedMethods.
# ExcludedMethods: refine
Metrics/BlockLength:
Max: 212
Max: 218

# Offense count: 2
# Configuration parameters: CountComments.
Expand Down
2 changes: 1 addition & 1 deletion lib/traject/macros/custom.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions spec/lib/traject/macros/custom_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2f42d91

Please sign in to comment.