diff options
| author | Zog | 2018-05-31 10:29:01 +0200 |
|---|---|---|
| committer | Zog | 2018-05-31 10:29:23 +0200 |
| commit | 5ef8fb2f8097041ff45307c8ffe415d78b7762f8 (patch) | |
| tree | 1048fb82558880bc55ec6b74831325bc51d2ae59 | |
| parent | 335d58df04f40dbf0840b02446ce0761d60d2027 (diff) | |
| download | chouette-core-5ef8fb2f8097041ff45307c8ffe415d78b7762f8.tar.bz2 | |
Fix SimpleInterface output to CSV
| -rw-r--r-- | app/models/simple_interface.rb | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/app/models/simple_interface.rb b/app/models/simple_interface.rb index d5feafb07..4da103c38 100644 --- a/app/models/simple_interface.rb +++ b/app/models/simple_interface.rb @@ -98,14 +98,15 @@ class SimpleInterface < ApplicationModel def write_output_to_csv cols = %i(line kind event message error) journal = self.journal && self.journal.map(&:symbolize_keys) - if journal && journal.size > 0 && journal.first[:row].present? + first_row = journal.find{|r| r[:row].present? } + if first_row.present? log "Writing output log" FileUtils.mkdir_p @output_dir - keys = journal.first[:row].map(&:first) + keys = first_row[:row].map(&:first) CSV.open(output_filepath, "w") do |csv| csv << cols + keys journal.each do |j| - csv << cols.map{|c| j[c]} + j[:row].map(&:last) + csv << cols.map{|c| j[c]} + (j[:row] || {}).map(&:last) end end log "Output written in #{output_filepath}", replace: true |
