Submit social housing lettings and sales data (CORE)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

27 lines
639 B

namespace :export do
desc "Export data to CSV"
task csv: :environment do
File.open("csv_export.csv", "w") do |file|
DATA_ARRAY.each do |row|
file.puts row.map { |val|
if val.nil?
"" # nil becomes empty
else
str = val.to_s
if str.include?(",") || str.include?("\n") || str.include?('"')
'"' + str.gsub('"', '""') + '"' # quote only when needed
else
str
end
end
}.join(",")
end
end
puts "CSV exported to csv_export.csv"
end
end
# array to convert goes here
DATA_ARRAY = []