bloopletech (owner)

Revisions

gist: 218628 Download_button fork
public
Public Clone URL: git://gist.github.com/218628.git
Embed All Files: show embed
csv_to_table.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/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