Wednesday, October 29, 2008

Transform a Twiki Table

I needed to change a TWiki table to make the rows become columns and columns become rows.

Ruby + 5 mins =

table = <<-TABLE
...paste table here...
TABLE

rows = (table.split "\n").collect { |line| line.split("|") }
puts (0.. rows[1].length).each { |col| puts "|#{rows.collect{ |row| row[col] }.join("|")}|" }

Ahhhh.. That could have been painful.

I love being a programmer. How do people that don't code handle this sort of problem?
Post a Comment

GitHub Projects