lib/marc_cleanup/bib_rubymarc_fixes.rb
def bad_utf8_fix(record)
    record.fields.each do |field|
      field_index = record.fields.index(field)
      if field.class == MARC::DataField
        field.subfields.each do |subfield|
          subfield_index = record.fields[field_index].subfields.index(subfield)
          record.fields[field_index].subfields[subfield_index].value.scrub!('').force_encoding('UTF-8')
        end
      else
        record.fields[field_index].value.scrub!('').force_encoding('UTF-8')
      end
    end
    record
  end
### Scrub invalid UTF-8 byte sequences within field values,
#     replacing with nothing; indicators, subfield codes, and tags must be
#     handled separately
Scrub invalid UTF-8 byte sequences within field values,
replacing with nothing; indicators, subfield codes, and tags must be
handled separately
Scrub invalid UTF - 8 byte sequences within field values replacing with nothing ; indicators subfield codes and tags must be handled separately
def bad_utf8_fix(record)
    record.fields.each do |field|
      field_index = record.fields.index(field)
      if field.class == MARC::DataField
        field.subfields.each do |subfield|
          subfield_index = record.fields[field_index].subfields.index(subfield)
          record.fields[field_index].subfields[subfield_index].value.scrub!('').force_encoding('UTF-8')
        end
      else
        record.fields[field_index].value.scrub!('').force_encoding('UTF-8')
      end
    end
    record
  end
def bad_utf8_fix ( record ) record . fields . each do | field | field_index = record . fields . index ( field ) if field . class == MARC :: DataField field . subfields . each do | subfield | subfield_index = record . fields [ field_index ] . subfields . index ( subfield ) record . fields [ field_index ] . subfields [ subfield_index ] . value . scrub! ( '' ) . force_encoding ( 'UTF-8' ) end else record . fields [ field_index ] . value . scrub! ( '' ) . force_encoding ( 'UTF-8' ) end end record end
Scrub invalid UTF-8 byte sequences within field values,
replacing with nothing; indicators, subfield codes, and tags must be
handled separately
Scrub invalid UTF - 8 byte sequences within field values replacing with nothing ; indicators subfield codes and tags must be handled separately
record