lib/dbf/table.rb in dbf-4.1.2 vs lib/dbf/table.rb in dbf-4.1.3
- old
+ new
@@ -1,9 +1,12 @@
module DBF
class FileNotFoundError < StandardError
end
+ class NoColumnsDefined < StandardError
+ end
+
# DBF::Table is the primary interface to a single DBF file and provides
# methods for enumerating and searching the records.
class Table
extend Forwardable
include Enumerable
@@ -173,13 +176,16 @@
# the database.
#
# @param [Integer] index
# @return [DBF::Record, NilClass]
def record(index)
+ raise DBF::NoColumnsDefined, 'The DBF file has no columns defined' if columns.empty?
+
seek_to_record(index)
return nil if deleted_record?
- DBF::Record.new(@data.read(record_length), columns, version, @memo)
+ record_data = @data.read(record_length)
+ DBF::Record.new(record_data, columns, version, @memo)
end
alias row record
# Dumps all records to a CSV file. If no filename is given then CSV is