Created
August 11, 2008 23:01
-
-
Save kastner/4965 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
#!/usr/bin/env ruby | |
def lines | |
@input ||= STDIN.read | |
lines = 0 | |
@input.each_line do |line| | |
line.split(/\|/).each_with_index do |c, i| | |
yield lines, c, i | |
end | |
lines += 1 | |
end | |
end | |
maxes = [] | |
lines do |l, c, i| | |
maxes[i] ||= 0 | |
maxes[i] = c.size if maxes[i] < c.size | |
end | |
output = [] | |
lines do |l, c, i| | |
output[l] ||= [] | |
output[l][i] = c.chomp + (" " * (maxes[i] - c.size)) | |
end | |
out = output.map { |l| l.join("|") } | |
puts out.join("\n") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment