module ReadOperations::InstanceMethods
Instance Methods¶ ↑
Defines behavior for instances of a subclass of Flat::File
regarding the reading and parsing of the file contents, line by line.
Public Instance Methods
each_record(io) { |create_record(line, lineno), line| ... }
click to toggle source
Iterate through each record (each line of the data file). The passed block is passed a new Record
representing the line.
s = SomeFile.new s.each_record(open('/path/to/file')) do |r| puts r.first_name end
# File lib/flat/read_operations.rb, line 30 def each_record io, &block io.each_line do |line| line.chop! next if line.length.zero? unless (self.width - line.length).zero? raise Errors::RecordLengthError, "length is #{line.length} but should be #{self.width}" end yield create_record(line, io.lineno), line end end