RosettaCodeData/Task/CSV-to-HTML-translation/Ruby/csv-to-html-translation-1.rb
Ingy döt Net 764da6cbbb CDE
2013-04-10 16:57:12 -07:00

17 lines
326 B
Ruby

require 'cgi'
puts '<table summary="csv2html program output">'
def row2html str, wrap = "td"
"<tr>" +
str.split(",").map { |cell| "<#{wrap}>#{CGI.escapeHTML cell}</#{wrap}>" }.join +
"</tr>"
end
puts row2html gets.chomp, "th" if ARGV.delete "header"
while str = gets
puts row2html str.chomp
end
puts "</table>"