lib/marc_cleanup/bib_rubymarc_fixes.rb
def fix_041(record)
    f041 = record.fields('041')
    return record if f041.empty?
    f041.each do |field|
      f_index = record.fields.index(field)
      new_field = MARC::DataField.new('041', field.indicator1, field.indicator2)
      field.subfields.each do |subfield|
        code = subfield.code
        val = subfield.value
        next unless val.size % 3 == 0
        langs = val.scan(/.../)
        langs.each do |lang|
          new_field.append(MARC::Subfield.new(code, lang))
        end
      end
      record.fields[f_index] = new_field
    end
    record
  end
### Split up subfields that contain multiple 3-letter language codes
Split up subfields that contain multiple 3-letter language codes
Split up subfields that contain multiple 3 - letter language codes
def fix_041(record)
    f041 = record.fields('041')
    return record if f041.empty?
    f041.each do |field|
      f_index = record.fields.index(field)
      new_field = MARC::DataField.new('041', field.indicator1, field.indicator2)
      field.subfields.each do |subfield|
        code = subfield.code
        val = subfield.value
        next unless val.size % 3 == 0
        langs = val.scan(/.../)
        langs.each do |lang|
          new_field.append(MARC::Subfield.new(code, lang))
        end
      end
      record.fields[f_index] = new_field
    end
    record
  end
def fix_041 ( record ) f041 = record . fields ( '041' ) return record if f041 . empty? f041 . each do | field | f_index = record . fields . index ( field ) new_field = MARC :: DataField . new ( '041' , field . indicator1 , field . indicator2 ) field . subfields . each do | subfield | code = subfield . code val = subfield . value next unless val . size % 3 == 0 langs = val . scan ( / ... / ) langs . each do | lang | new_field . append ( MARC :: Subfield . new ( code , lang ) ) end end record . fields [ f_index ] = new_field end record end
Split up subfields that contain multiple 3-letter language codes
Split up subfields that contain multiple 3 - letter language codes
record