Class: MarkdownTable
- Defined in:
- lib/almirah/doc_items/markdown_table.rb
Instance Attribute Summary collapse
-
#column_names ⇒ Object
Returns the value of attribute column_names.
-
#rows ⇒ Object
Returns the value of attribute rows.
Instance Method Summary collapse
- #addRow(row) ⇒ Object
-
#initialize(heading_row) ⇒ MarkdownTable
constructor
A new instance of MarkdownTable.
- #to_html ⇒ Object
Constructor Details
#initialize(heading_row) ⇒ MarkdownTable
Returns a new instance of MarkdownTable.
8 9 10 11 |
# File 'lib/almirah/doc_items/markdown_table.rb', line 8 def initialize(heading_row) @column_names = heading_row.split('|') @rows = Array.new end |
Instance Attribute Details
#column_names ⇒ Object
Returns the value of attribute column_names.
5 6 7 |
# File 'lib/almirah/doc_items/markdown_table.rb', line 5 def column_names @column_names end |
#rows ⇒ Object
Returns the value of attribute rows.
6 7 8 |
# File 'lib/almirah/doc_items/markdown_table.rb', line 6 def rows @rows end |
Instance Method Details
#addRow(row) ⇒ Object
13 14 15 16 |
# File 'lib/almirah/doc_items/markdown_table.rb', line 13 def addRow(row) columns = row.split('|') @rows.append(columns) end |
#to_html ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/almirah/doc_items/markdown_table.rb', line 18 def to_html s = '' if @@htmlTableRenderInProgress s += "</table>" @@htmlTableRenderInProgress = false end s += "<table>\n\r" s += "\t<thead>" @column_names.each do |h| s += " <th>#{h}</th>" end s += " </thead>\n\r" @rows.each do |row| s += "\t<tr>\n\r" row.each do |col| s += "\t\t<td>#{col}</td>\n\r" end s += "\t</tr>\n\r" end s += "</table>\n\r" return s end |