Class: MARC::ForgivingReader

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/marc/reader.rb

Overview

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.

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ ForgivingReader

Returns a new instance of ForgivingReader.



173
174
175
176
177
178
179
180
181
# File 'lib/marc/reader.rb', line 173

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

Instance Method Details

#eachObject



184
185
186
187
188
189
190
191
192
193
194
# File 'lib/marc/reader.rb', line 184

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