Skip to content

Commit

Permalink
test the extra_space_fix method
Browse files Browse the repository at this point in the history
  • Loading branch information
mzelesky committed Nov 13, 2024
1 parent b385897 commit fc0a637
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/marc_cleanup/variable_fields.rb
Original file line number Diff line number Diff line change
Expand Up @@ -241,28 +241,28 @@ def extra_space_fix(record)
curr_subfield += 1
next if subfield.value.nil?

record.fields[field_index].subfields[curr_subfield].value = extra_space_gsub(subfield.value)
record.fields[field_index].subfields[curr_subfield].value = extra_space_gsub(subfield.value.dup)
end
when '533'
field.subfields.each do |subfield|
curr_subfield += 1
next if subfield.code == '7' || subfield.value.nil?

record.fields[field_index].subfields[curr_subfield].value = extra_space_gsub(subfield.value)
record.fields[field_index].subfields[curr_subfield].value = extra_space_gsub(subfield.value.dup)
end
when /^7[6-8]./
field.subfields.each do |subfield|
curr_subfield += 1
next if subfield.code =~ /[^a-v3-8]/ || subfield.value.nil?

record.fields[field_index].subfields[curr_subfield].value = extra_space_gsub(subfield.value)
record.fields[field_index].subfields[curr_subfield].value = extra_space_gsub(subfield.value.dup)
end
when /^8../
field.subfields.each do |subfield|
curr_subfield += 1
next if %w[w 7].include?(subfield.code) || subfield.value.nil?

record.fields[field_index].subfields[curr_subfield].value = extra_space_gsub(subfield.value)
record.fields[field_index].subfields[curr_subfield].value = extra_space_gsub(subfield.value.dup)
end
end
end
Expand Down
57 changes: 57 additions & 0 deletions spec/variable_fields/extra_spaces_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,60 @@
end
end
end

RSpec.describe 'extra_space_fix' do
let(:record) { MARC::Record.new_from_hash('fields' => fields, 'leader' => leader) }
let(:leader) { '01104naa a2200289 i 4500' }

context '1xx field has extra spaces' do
let(:fields) do
[
{ '100' => { 'ind1' => '0',
'ind2' => ' ',
'subfields' => [{ 'a' => 'Candy wrapper.' }] } }
]
end
it 'removes the extra spaces' do
expect(MarcCleanup.extra_space_fix(record)['100']['a']).to eq 'Candy wrapper.'
end
end

context '533 field has extra spaces in a positionally-defined subfield' do
let(:fields) do
[
{ '533' => { 'ind1' => ' ',
'ind2' => ' ',
'subfields' => [
{ 'a' => "Positive\u3000photo" },
{ '7' => 's1989 nyu a'}] } }
]
end
it 'does not modify the positionally-defined subfield' do
expect(MarcCleanup.extra_space_fix(record)['533']['7']).to eq 's1989 nyu a'
end
end

context '775 field has extra spaces in main entry' do
let(:fields) do
[
{ '775' => { 'ind1' => '0',
'ind2' => ' ',
'subfields' => [ { 'a' => 'Modernist thought' }] } }]
end
it 'removes the extra spaces' do
expect(MarcCleanup.extra_space_fix(record)['775']['a']).to eq 'Modernist thought'
end
end

context '830 field has no extra spaces in main entry' do
let(:fields) do
[
{ '830' => { 'ind1' => ' ',
'ind2' => '4',
'subfields' => [ { 'a' => 'The modern world.' }] } }]
end
it 'does not modify the record' do
expect(MarcCleanup.extra_space_fix(record)['830']['a']).to eq 'The modern world.'
end
end
end

0 comments on commit fc0a637

Please sign in to comment.