func escape(str) { str.trans(« & < > », « & < > ») } func tag(t, d) { "<#{t}>#{d}" } func csv2html(str) { var template = <<-'EOT' Some Text %s
EOT template.sprintf(escape(str).lines.map{ |line| tag('tr', line.split(',').map{|cell| tag('td', cell) }.join) }.join("\n") ) } var str = <<'EOT'; Character,Speech The multitude,The messiah! Show us the messiah! Brians mother,Now you listen here! He's not the messiah; he's a very naughty boy! Now go away! The multitude,Who are you? Brians mother,I'm his mother; that's who! The multitude,Behold his mother! Behold his mother! EOT print csv2html(str)