lib/dbf/table.rb in dbf-1.2.2 vs lib/dbf/table.rb in dbf-1.2.4
- old
+ new
@@ -133,10 +133,11 @@
#
# @param [optional String] path Defaults to basename of dbf file
def to_csv(path = nil)
path = File.basename(@data.path, '.dbf') + '.csv' if path.nil?
FCSV.open(path, 'w', :force_quotes => true) do |csv|
+ csv << columns.map {|c| c.name}
each do |record|
csv << record.to_a
end
end
end
@@ -186,11 +187,11 @@
# @yield [optional DBF::Record]
# @return [Array]
def find_all(options, &block)
results = []
each do |record|
- if all_values_match?(record, options)
+ if record && all_values_match?(record, options)
if block_given?
yield(record)
else
results << record
end
@@ -203,10 +204,10 @@
#
# @param [Hash] options
# @return [DBF::Record, nil]
def find_first(options)
each do |record|
- return record if all_values_match?(record, options)
+ return record if record && all_values_match?(record, options)
end
nil
end
# Do all search parameters match?
\ No newline at end of file