Class: Opmac2html::TableBuilder
- Inherits:
-
Object
- Object
- Opmac2html::TableBuilder
- Defined in:
- lib/opmac2html/table_builder.rb
Overview
Builder for tables
Constant Summary collapse
- SPAN =
'\\multispan'
Instance Method Summary collapse
- #add_caption(text) ⇒ Object
- #add_row(cells) ⇒ Object
- #cell_to_s(cell) ⇒ Object
-
#initialize ⇒ TableBuilder
constructor
A new instance of TableBuilder.
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ TableBuilder
Returns a new instance of TableBuilder.
6 7 8 9 |
# File 'lib/opmac2html/table_builder.rb', line 6 def initialize @header = true @table = ["\n"] end |
Instance Method Details
#add_caption(text) ⇒ Object
24 25 26 |
# File 'lib/opmac2html/table_builder.rb', line 24 def (text) @table.insert 1, "<caption>#{text}</caption>\n" end |
#add_row(cells) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# 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) ⇒ Object
28 29 30 31 32 |
# 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 ⇒ Object
34 35 36 |
# File 'lib/opmac2html/table_builder.rb', line 34 def to_s @table.join end |