-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test extra space methods #132
Conversation
fc0a637
to
471fb4f
Compare
471fb4f
to
d6cdfb2
Compare
@sandbergja Could you please review if you have time? I am inching closer to 100% coverage. These particular methods are deep in the weeds, but they do a lot to clean up presentation of records. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @mzelesky ! 🪈 I had one potential refactoring idea, definitely not a blocker.
lib/marc_cleanup/variable_fields.rb
Outdated
field_index = record.fields.index(field) | ||
curr_subfield = -1 | ||
case field.tag | ||
when /^[1-469]..|0[2-9].|01[1-9]|7[0-5].|5[0-24-9].|53[0-24-9]/ | ||
field.subfields.each do |subfield| | ||
curr_subfield += 1 | ||
next if subfield.value.nil? | ||
|
||
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.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.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.dup) | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One potential refactor, which would remove the need to keep track of the curr_subfield
and the field_index
:
field_index = record.fields.index(field) | |
curr_subfield = -1 | |
case field.tag | |
when /^[1-469]..|0[2-9].|01[1-9]|7[0-5].|5[0-24-9].|53[0-24-9]/ | |
field.subfields.each do |subfield| | |
curr_subfield += 1 | |
next if subfield.value.nil? | |
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.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.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.dup) | |
end | |
end | |
case field.tag | |
when /^[1-469]..|0[2-9].|01[1-9]|7[0-5].|5[0-24-9].|53[0-24-9]/ | |
field.subfields.map! do |subfield| | |
next subfield if subfield.value.nil? | |
subfield.value = extra_space_gsub(subfield.value.dup) | |
subfield | |
end | |
when '533' | |
field.subfields.map! do |subfield| | |
next subfield if subfield.code == '7' || subfield.value.nil? | |
subfield.value = extra_space_gsub(subfield.value.dup) | |
subfield | |
end | |
when /^7[6-8]./ | |
field.subfields.map! do |subfield| | |
next subfield if subfield.code =~ /[^a-v3-8]/ || subfield.value.nil? | |
subfield.value = extra_space_gsub(subfield.value.dup) | |
subfield | |
end | |
when /^8../ | |
field.subfields.map! do |subfield| | |
next subfield if %w[w 7].include?(subfield.code) || subfield.value.nil? | |
subfield.value = extra_space_gsub(subfield.value.dup) | |
subfield | |
end |
@sandbergja Can you take another look? It turns out I didn't need to keep track of the field and subfield indexes at all; I just modified it as part of the block. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great to me, I like the refactor. Thanks, @mzelesky ! 🪈
Tests
extra_spaces?
andextra_space_fix
and moves the methods together in variable_fields.rb.Completes testing of
empty_subfields?