Created
September 15, 2014 15:18
-
-
Save TrevorS/b0b45c3ecc4048ad17a7 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 | |
# encoding: utf-8 | |
input = "a, b, c\nd, e, f\ng, h, i\n" | |
lines = input.split("\n") | |
rows = lines.map { |l| l.gsub(/ *, */, ' | ') } | |
col_count = rows.first.scan(/\|/).count + 1 | |
with_header = rows.insert(1, "|#{'---|' * col_count}") | |
output = with_header.join("\n") | |
puts "output:\n#{output}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment