lib/marc_cleanup/bib_rubymarc_fixes.rb
def replace_field(field_string:, replacement_field:, record:)
    orig_string = field_string.dup
    orig_string.scrub!('')
    orig_string.strip!
    field_tag = orig_string[0..2]
    target_fields = record.fields(field_tag)
    return record if target_fields.empty?
    target_fields.each do |field|
      string = field.to_s
      string.scrub!('')
      string.strip!
      next unless string == orig_string
      field_index = record.fields.index(field)
      record.fields[field_index] = replacement_field
    end
    record
  end
### Replace field from a record that matches a string version of the field
###   with the supplied field object, which can be either a ControlField
###   or a DataField
Replace field from a record that matches a string version of the field
with the supplied field object, which can be either a ControlField
or a DataField
Replace field from a record that matches a string version of the field with the supplied field object which can be either a ControlField or a DataField
def replace_field(field_string:, replacement_field:, record:)
    orig_string = field_string.dup
    orig_string.scrub!('')
    orig_string.strip!
    field_tag = orig_string[0..2]
    target_fields = record.fields(field_tag)
    return record if target_fields.empty?
    target_fields.each do |field|
      string = field.to_s
      string.scrub!('')
      string.strip!
      next unless string == orig_string
      field_index = record.fields.index(field)
      record.fields[field_index] = replacement_field
    end
    record
  end
def replace_field ( field_string : , replacement_field : , record : ) orig_string = field_string . dup orig_string . scrub! ( '' ) orig_string . strip! field_tag = orig_string [ 0 .. 2 ] target_fields = record . fields ( field_tag ) return record if target_fields . empty? target_fields . each do | field | string = field . to_s string . scrub! ( '' ) string . strip! next unless string == orig_string field_index = record . fields . index ( field ) record . fields [ field_index ] = replacement_field end record end
Replace field from a record that matches a string version of the field
with the supplied field object, which can be either a ControlField
or a DataField
Replace field from a record that matches a string version of the field with the supplied field object which can be either a ControlField or a DataField
field_string
replacement_field
record