add generation csv service
This commit is contained in:
parent
882ee74f88
commit
181e237cf0
1 changed files with 19 additions and 0 deletions
19
app/services/generate_open_data_csv_service.rb
Normal file
19
app/services/generate_open_data_csv_service.rb
Normal file
|
@ -0,0 +1,19 @@
|
|||
class GenerateOpenDataCsvService
|
||||
def self.save_csv_to_tmp(file_name, data)
|
||||
f = Tempfile.create(["#{file_name}_#{date_last_month}", '.csv'], 'tmp')
|
||||
f << generate_csv(file_name, data)
|
||||
f.rewind
|
||||
yield f if block_given?
|
||||
f.close
|
||||
end
|
||||
|
||||
def self.date_last_month
|
||||
Date.today.prev_month.strftime("%B")
|
||||
end
|
||||
|
||||
def self.generate_csv(file_name, data)
|
||||
headers = ["mois", file_name]
|
||||
data = [[date_last_month, data]]
|
||||
SpreadsheetArchitect.to_csv(headers: headers, data: data)
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue