class MARC::ForgivingReader

The one downside to this is that ForgivingReader will assume that the order of the fields in the directory is the same as the order of fields in the field data. Hopefully this will be the case, but it is not 100% guranteed which is why the normal behavior of Reader is encouraged.

Public Class Methods

new(file) click to toggle source
# File lib/marc/reader.rb, line 177
def initialize(file)
  if file.class == String
    @handle = File.new(file)
  elsif file.respond_to?("read", 5)
    @handle = file
  else
    throw "must pass in path or File object"        
  end
end

Public Instance Methods

each() { |record| ... } click to toggle source
# File lib/marc/reader.rb, line 188
def each 
  @handle.each_line(END_OF_RECORD) do |raw| 
    begin
      record = MARC::Reader.decode(raw, :forgiving => true)
      yield record 
    rescue StandardError => e
      # caught exception just keep barrelling along
      # TODO add logging
    end
  end
end