Sha256: 936cfca2a6b444576773189cca04329b37209fc44d69190892442376a2d3ae26

Contents?: true

Size: 672 Bytes

Versions: 1

Compression:

Stored size: 672 Bytes

Contents

require 'csv'

module PanicBoardData
  class Table

    attr_accessor :data, :widths

    def to_html
      result = "<table>"

      if data
        data.each do |record|
          result << "<tr>"
          record.each_with_index do |item, index|
            if widths && widths[index]
              result << "<td style=\"width: #{widths[index]}px\">#{item}</td>"
            else
              result << "<td>#{item}</td>"
            end
          end
          result << "</tr>"
        end
      end

      result << "</table>"
    end

    def self.to_csv data
      ::CSV.generate do |csv|
        data.each { |row| csv << row }
      end.strip
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
panic_board_data-0.0.7 lib/panic_board_data/table.rb