class MARC::AlephSequential::Reader
Attributes
current_id[RW]
lines[R]
Public Class Methods
new(filename_or_io, opts={})
click to toggle source
# File lib/marc_alephsequential/reader.rb, line 34 def initialize(filename_or_io, opts={}) @areader = ASLineReader.new(filename_or_io) end
Public Instance Methods
each() { |to_record| ... }
click to toggle source
# File lib/marc_alephsequential/reader.rb, line 38 def each unless block_given? return enum_for(:each) end agroup = ASLineGroup.new while @areader.has_next? nextid = @areader.peek.id if nextid != @current_id && @areader.peek.valid_id? begin yield agroup.to_record unless agroup.empty? rescue RuntimeError => e yield ErrorRecord.new(e) end agroup = ASLineGroup.new @current_id = nextid else agroup.add @areader.next end end # yield whatever is left, unless there's nothing left begin yield agroup.to_record unless agroup.empty? rescue RuntimeError => e yield ErrorRecord.new(e) end end