Skip to content

Instantly share code, notes, and snippets.

@ayosec
Created August 8, 2010 23:00
Show Gist options
  • Save ayosec/514672 to your computer and use it in GitHub Desktop.
Save ayosec/514672 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
# Format columns in the Cucumber style
input = STDIN.read
margin_left = input =~ /\A(\s+)\S/ && $1
rows = input.split("\n").map {|line| line.strip.scan(/\|([^|]+)/).map {|column| column.first.strip } }
column_widths = rows.transpose.map {|column| column.map {|c| c.size }.max }
rows.each do |row|
print margin_left
row.each_with_index do |column, index|
print "| %-#{column_widths[index]}s " % column
end
puts "|"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment