def fix_leader!(leader)

      if leader.length < 24
        # pad it to 24 bytes, leader is supposed to be 24 bytes
        leader.replace(  leader.ljust(24, ' ')  )
      elsif leader.length > 24
        # Also a problem, slice it
        leader.replace( leader.byteslice(0, 24))
      end
      # http://www.loc.gov/marc/bibliographic/ecbdldrd.html
      leader[10..11] = '22'
      leader[20..23] = '4500'

      if settings['horizon.destination_encoding'] == "UTF8"
        leader[9] = 'a'
      end

      # leader should only have ascii chars in it; invalid non-ascii
      # chars can cause ruby encoding problems down the line.
      # additionally, a force_encoding may be neccesary to
      # deal with apparent weird hard to isolate jruby bug prob same one
      # as at https://github.com/jruby/jruby/issues/886
      leader.force_encoding('ascii')

      unless leader.valid_encoding?
        # replace any non-ascii chars with a space.

        # Can't access leader.chars when it's not a valid encoding
        # without a weird index out of bounds exception, think it's
        # https://github.com/jruby/jruby/issues/886
        # Grr.

        #leader.replace( leader.chars.collect { |c| c.valid_encoding? ? c : ' ' }.join('') )
        leader.replace(leader.split('').collect { |c| c.valid_encoding? ? c : ' ' }.join(''))
      end



    end
def fix_leader!(leader)

      if leader.length < 24
        # pad it to 24 bytes, leader is supposed to be 24 bytes
        leader.replace(  leader.ljust(24, ' ')  )
      elsif leader.length > 24
        # Also a problem, slice it
        leader.replace( leader.byteslice(0, 24))
      end
      # http://www.loc.gov/marc/bibliographic/ecbdldrd.html
      leader[10..11] = '22'
      leader[20..23] = '4500'

      if settings['horizon.destination_encoding'] == "UTF8"
        leader[9] = 'a'
      end

      # leader should only have ascii chars in it; invalid non-ascii
      # chars can cause ruby encoding problems down the line.
      # additionally, a force_encoding may be neccesary to
      # deal with apparent weird hard to isolate jruby bug prob same one
      # as at https://github.com/jruby/jruby/issues/886
      leader.force_encoding('ascii')

      unless leader.valid_encoding?
        # replace any non-ascii chars with a space.

        # Can't access leader.chars when it's not a valid encoding
        # without a weird index out of bounds exception, think it's
        # https://github.com/jruby/jruby/issues/886
        # Grr.

        #leader.replace( leader.chars.collect { |c| c.valid_encoding? ? c : ' ' }.join('') )
        leader.replace(leader.split('').collect { |c| c.valid_encoding? ? c : ' ' }.join(''))
      end



    end
Mutate string passed in to fix leader bytes for marc21