lib/dbf/reader.rb in dbf-0.4.2 vs lib/dbf/reader.rb in dbf-0.4.3
- old
+ new
@@ -148,10 +148,19 @@
@version, @record_count, @header_length, @record_length = @data_file.read(DBF_HEADER_SIZE).unpack('H2xxxVvv')
@field_count = (@header_length - DBF_HEADER_SIZE + 1) / DBF_HEADER_SIZE
end
def get_field_descriptors
- @fields = Array.new(@field_count) {|i| Field.new(*@data_file.read(32).unpack('a10xax4CC'))}
+ @fields = []
+ @field_count.times do
+ name, type, length, decimal = @data_file.read(32).unpack('a10xax4CC')
+ if length > 0 && !name.strip.empty?
+ @fields << Field.new(name.strip, type, length, decimal)
+ end
+ end
+ # adjust field count
+ @field_count = @fields.size
+ @fields
end
def get_memo_header_info
@memo_file.rewind
if @memo_file_format == :fpt