Skip to content

Instantly share code, notes, and snippets.

@kastner
Created August 11, 2008 23:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kastner/4965 to your computer and use it in GitHub Desktop.
Save kastner/4965 to your computer and use it in GitHub Desktop.
#!/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