lib/dbf/table.rb in dbf-1.6.0 vs lib/dbf/table.rb in dbf-1.6.1
- old
+ new
@@ -1,11 +1,9 @@
module DBF
# DBF::Table is the primary interface to a single DBF file and provides
# methods for enumerating and searching the records.
-
- # TODO set record_length to length of actual used column lengths
class Table
include Enumerable
DBF_HEADER_SIZE = 32
@@ -58,12 +56,12 @@
# the database.
#
# @param [Fixnum] index
# @return [DBF::Record, NilClass]
def record(index)
- seek_to_record(index)
- current_record
+ seek(index * @record_length)
+ deleted_record? ? nil : DBF::Record.new(@data.read(@record_length), columns, version, @memo)
end
alias_method :row, :record
# Human readable version description
@@ -194,14 +192,10 @@
def deleted_record? #nodoc
@data.read(1).unpack('a') == ['*']
end
- def current_record #nodoc
- deleted_record? ? nil : DBF::Record.new(@data.read(@record_length), columns, version, @memo)
- end
-
def get_header_info #nodoc
@data.rewind
@version, @record_count, @header_length, @record_length, encoding_key =
@data.read(DBF_HEADER_SIZE).unpack("H2 x3 V v2 x17H2")
@encoding = self.class.encodings[encoding_key] if "".respond_to? :encoding
@@ -209,23 +203,19 @@
def seek(offset) #nodoc
@data.seek @header_length + offset
end
- def seek_to_record(index) #nodoc
- seek index * @record_length
- end
-
def csv_class #nodoc
CSV.const_defined?(:Reader) ? FCSV : CSV
end
def default_csv_path #nodoc
File.basename(@data.path, '.dbf') + '.csv'
end
def self.encodings
- @encodings ||= YAML.load_file(File.expand_path("../encodings.yml", __FILE__))
+ @encodings ||= YAML.load File.read(File.expand_path("../encodings.yml", __FILE__))
end
end
end