|
|
@@ -29,14 +29,19 @@ module Petrify |
|
|
|
# https://support.google.com/webmasters/answer/183668?hl=en&ref_topic=4581190 |
|
|
|
end |
|
|
|
|
|
|
|
# Write a CSV file |
|
|
|
# Write a CSV file from an array of hashes (or an empty array) |
|
|
|
def self.csv(path_items, filename, data) |
|
|
|
dir = create_path(path_items) |
|
|
|
fn = File.join(dir, filename + '.csv') |
|
|
|
|
|
|
|
csv_string = CSV.generate do |csv| |
|
|
|
csv << data.first.keys # header row |
|
|
|
data.each { |row| csv << row.values } |
|
|
|
if data.size > 0 |
|
|
|
csv_string = CSV.generate do |csv| |
|
|
|
csv << data.first.keys # header row |
|
|
|
data.each { |row| csv << row.values } |
|
|
|
end |
|
|
|
else |
|
|
|
# There's no data so write an empty file (no header row either) |
|
|
|
csv_string = '' |
|
|
|
end |
|
|
|
|
|
|
|
File.write(fn, csv_string) |
|
|
|