Skip to content

Instantly share code, notes, and snippets.

@bloopletech
Created October 26, 2009 13:01
Show Gist options
  • Save bloopletech/218628 to your computer and use it in GitHub Desktop.
Save bloopletech/218628 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
require 'csv'
out = ""
rows = []
CSV.open(ARGV[0] || "changes.csv", 'r').each { |row_in| rows << row_in.map { |cell| cell.nil? ? "" : cell.to_s } }
max_lengths = {}
rows.each do |row|
row.each_with_index { |cell, i| max_lengths[i] = cell.length if !max_lengths.key?(i) || max_lengths[i] < cell.length }
end
rows.each do |row|
out << "|"
row.each_with_index { |cell, i| out << " #{cell.ljust(max_lengths[i])} |" }
out << "\n"
end
puts out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment