19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/marty/content_handler.rb', line 19
def self.export(data, format, name)
begin
case format
when "csv"
res = data.is_a?(String) ? data : Marty::DataExporter.to_csv(data)
when "xlsx"
res = Marty::Xl.spreadsheet(data).to_stream.read
when "zip"
res = to_zip(data)
when nil, "json"
res, format = data.to_json, "json"
when "html"
res = data.to_s
else
res, format = {error: "Unknown format: #{format}"}.to_json, "json"
end
rescue => exc
res, format =
{error: "Failed conversion #{format}: #{exc}"}.to_json, "json"
end
type, disposition = GEN_FORMATS[format]
return [res, type, disposition, "#{name}.#{format}"]
end
|