class Webservice::ResponseHandler::Tabular
Tabular
helper/support class
Attributes
headers[R]
rows[R]
Public Class Methods
new( headers, rows )
click to toggle source
# File lib/webservice/base/response_handler.rb, line 200 def initialize( headers, rows ) @headers = headers @rows = rows end
Public Instance Methods
to_csv( opts={} )
click to toggle source
# File lib/webservice/base/response_handler.rb, line 205 def to_csv( opts={} ) ## allow changing of column/value separator (col_sep) - why? why not? ## :col_sep => "\t" ## :col_sep => ";" pp self CSV.generate( headers: true ) do |csv| csv << headers rows.each do |row| csv << row end end end
to_html_table( opts={} )
click to toggle source
# File lib/webservice/base/response_handler.rb, line 221 def to_html_table( opts={} ) ## todo/fix: html escape values - why? why not?? pp self buf = "" buf << "<table>\n" buf << " <tr>" headers.each do |header| buf << "<th>#{header}</th>" end buf << "</tr>\n" rows.each do |row| buf << " <tr>" row.each do |value| buf << "<td>#{value}</td>" end buf << "</tr>\n" end buf << "</table>\n" buf end