Skip to content

Instantly share code, notes, and snippets.

@TrevorS
Created September 15, 2014 15:18
Show Gist options
  • Save TrevorS/b0b45c3ecc4048ad17a7 to your computer and use it in GitHub Desktop.
Save TrevorS/b0b45c3ecc4048ad17a7 to your computer and use it in GitHub Desktop.
#!/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