class Opmac2html::TableBuilder
Builder for tables
Constants
- SPAN
Public Class Methods
new()
click to toggle source
# File lib/opmac2html/table_builder.rb, line 6 def initialize @header = true @table = ["\n"] end
Public Instance Methods
add_caption(text)
click to toggle source
# File lib/opmac2html/table_builder.rb, line 24 def add_caption(text) @table.insert 1, "<caption>#{text}</caption>\n" end
add_row(cells)
click to toggle source
# File lib/opmac2html/table_builder.rb, line 11 def add_row(cells) @table << "<tr>\n" cells.each do |cell| span_index = cell.index(SPAN) span = cell[span_index + SPAN.length] if span_index part = cell.partition SPAN newcell = part[0] + (span_index ? part[2][1..-1] : '') @table << cell_to_s([@header, newcell, span]) end @table << "</tr>\n" @header = false end
cell_to_s(cell)
click to toggle source
# File lib/opmac2html/table_builder.rb, line 28 def cell_to_s(cell) tag = cell[0] ? 'th' : 'td' attr = cell[2] ? " colspan=\"#{cell[2]}\"" : '' "<#{tag}#{attr}>#{cell[1]}</#{tag}>\n" end
to_s()
click to toggle source
# File lib/opmac2html/table_builder.rb, line 34 def to_s @table.join end