|
|
|
|
@ -10,22 +10,27 @@ module Csv
|
|
|
|
|
def prepare_csv(schemes) |
|
|
|
|
CSV.generate(headers: true) do |csv| |
|
|
|
|
csv << attributes |
|
|
|
|
schemes.find_each do |scheme| |
|
|
|
|
if @download_type == "schemes" |
|
|
|
|
csv << scheme_attributes.map { |attribute| scheme_value(attribute, scheme) } |
|
|
|
|
else |
|
|
|
|
scheme.locations.each do |location| |
|
|
|
|
|
|
|
|
|
case @download_type |
|
|
|
|
when "schemes" |
|
|
|
|
schemes.each do |scheme| |
|
|
|
|
csv << scheme_attributes.map { |attribute| scheme_value(attribute, scheme) } |
|
|
|
|
end |
|
|
|
|
when "locations" |
|
|
|
|
schemes.each do |scheme| |
|
|
|
|
scheme.locations.each do |location| |
|
|
|
|
csv << [scheme.id_to_display] + location_attributes.map { |attribute| location_value(attribute, location) } |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
when "combined" |
|
|
|
|
schemes.each do |scheme| |
|
|
|
|
scheme.locations.each do |location| |
|
|
|
|
csv << scheme_attributes.map { |attribute| scheme_value(attribute, scheme) } + location_attributes.map { |attribute| location_value(attribute, location) } |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
private |
|
|
|
|
|
|
|
|
|
|