lib/dbf/table.rb in dbf-1.0.8 vs lib/dbf/table.rb in dbf-1.0.9
- old
+ new
@@ -63,15 +63,10 @@
yield DBF::Record.new(self)
end
end
end
- # def get_record_from_file(index)
- # seek_to_record(@db_index[index])
- # Record.new(self)
- # end
-
# Returns a DBF::Record (or nil if the record has been marked for deletion) for the record at <tt>index</tt>.
def record(index)
records[index]
end
@@ -153,9 +148,19 @@
# physical database file. See the documentation for the records method for
# information on how these two methods differ.
def get_record_from_file(index)
seek_to_record(@db_index[index])
Record.new(self)
+ end
+
+ # Dumps all records into a CSV file
+ def to_csv(filename = nil)
+ filename = File.basename(@data.path, '.dbf') + '.csv' if filename.nil?
+ FCSV.open(filename, 'w', :force_quotes => true) do |csv|
+ records.each do |record|
+ csv << record.to_a
+ end
+ end
end
private
def open_memo(file)
\ No newline at end of file