Class: MARC::ForgivingReader
- Inherits:
-
Object
- Object
- MARC::ForgivingReader
- 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
- #each ⇒ Object
-
#initialize(file) ⇒ ForgivingReader
constructor
A new instance of ForgivingReader.
Constructor Details
#initialize(file) ⇒ ForgivingReader
Returns a new instance of ForgivingReader.
169 170 171 172 173 174 175 176 177 |
# File 'lib/marc/reader.rb', line 169 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
#each ⇒ Object
180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/marc/reader.rb', line 180 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 |