Skip to content

Instantly share code, notes, and snippets.

@svenfuchs

svenfuchs/csv2md

Last active Aug 29, 2015
Embed
What would you like to do?
convert csv to markdown
#!/usr/bin/env ruby
require 'csv'
filename = ARGV.shift
def format(questions, answers)
answers.map.with_index do |answer, ix|
"##### #{questions[ix]}\n\n#{answer}\n\n"
end
end
data = CSV.parse(File.read(filename))
questions = data.shift
blocks = data.map.with_index do |answers, ix|
answers = answers.select { |answer| answer && !answer.empty? }
["## Reply #{ix + 1}", format(questions, answers)]
end
blocks.unshift("# Feedback from #{filename.sub('.csv', '').capitalize}")
puts blocks.join("\n")
# install
curl https://gist.githubusercontent.com/svenfuchs/e5a4ccfb5ff2b887cbbf/raw/csv2md > csv2md
chmod +x csv2md
brew install gist
# usage
./csv2md something.csv > something.md
./csv2md something.csv | gist -p -f something.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment