Created
August 16, 2016 03:49
-
-
Save cattaka/51b126cf8aa8688fcc85bf07324731c4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def dump_values(obj) | |
results = "" | |
obj.keys.each do |key| | |
results += key.to_s + "\t" + obj[key].to_s + "\n" | |
end | |
results | |
end | |
def dump_tsv(rows) | |
keys = rows.map do |row| | |
if (row.is_a?(ActiveRecord::Base)) | |
row.attributes.keys | |
else | |
row.keys | |
end | |
end.flatten.uniq | |
data = rows.map do |row| | |
keys.map{ |key| row[key].to_s.gsub(/(\n)/, "\\n").gsub(/(\t)/, "\\t") }.join("\t") | |
end.join("\n") | |
keys.join("\t") + "\n" + data | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment