Last active
August 29, 2015 14:14
-
-
Save svenfuchs/e5a4ccfb5ff2b887cbbf to your computer and use it in GitHub Desktop.
convert csv to markdown
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
#!/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") |
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
# 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