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
46
|
# File 'lib/marty/content_handler.rb', line 20
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', 'pdf'
res = data.to_s
else
res, format = { error: "Unknown format: #{format}" }.to_json, 'json'
end
rescue StandardError => e
res, format =
{ error: "Failed conversion #{format}: #{e}" }.to_json, 'json'
end
type, disposition = GEN_FORMATS[format]
[res, type, disposition, "#{name}.#{format}"]
end
|