Class: MARC::ForgivingReader
Overview
Like Reader ForgivingReader lets you read in a batch of MARC21 records but it does not use record lengths and field byte offets found in the leader and directory. It is not unusual to run across MARC records which have had their offsets calculated wrong. In situations like this the vanilla Reader may fail, and you can try to use 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.
NOTE: ForgivingReader may have unpredictable results when used with marc records with char encoding other than system default (usually UTF8), especially if you have Encoding.default_internal set.
Implemented a sub-class of Reader over-riding #each, so we still get DRY Reader’s #initialize with proper char encoding options and handling.
Instance Method Summary collapse
Methods inherited from Reader
#decode, decode, #each_raw, #initialize, set_encoding
Constructor Details
This class inherits a constructor from MARC::Reader
Instance Method Details
#each ⇒ Object
483 484 485 486 487 488 489 490 491 |
# File 'lib/marc/reader.rb', line 483 def each @handle.each_line(END_OF_RECORD) do |raw| record = MARC::Reader.decode(raw, @encoding_options.merge(forgiving: true)) yield record rescue # caught exception just keep barrelling along # TODO add logging end end |