class TablePal::PlainText
Attributes
coloured[R]
output[R]
result[R]
table[R]
Public Class Methods
new(table:, coloured: false, output: true)
click to toggle source
# File lib/plain_text.rb, line 6 def initialize(table:, coloured: false, output: true) @table = table @coloured = coloured @output = output @result = '' table.rows.each do |row| print_row(row) end end
Public Instance Methods
to_s()
click to toggle source
# File lib/plain_text.rb, line 17 def to_s result end
Private Instance Methods
add_chars(chars)
click to toggle source
# File lib/plain_text.rb, line 99 def add_chars(chars) @result.concat(chars) print chars if output end
add_new_line()
click to toggle source
# File lib/plain_text.rb, line 105 def add_new_line @result.concat("\n") puts if output end
empty()
click to toggle source
# File lib/plain_text.rb, line 86 def empty table.columns.map do |column| char = ' ' add_chars column.left_border add_chars column.left_padding_char(char) add_chars char * column.width add_chars column.right_padding_char(char) add_chars column.right_border end add_new_line end
print_cell(cell)
click to toggle source
# File lib/plain_text.rb, line 65 def print_cell(cell) add_chars cell.column.left_border add_chars cell.column.left_padding add_chars cell.formatted(justified: true, coloured: coloured) add_chars cell.column.right_padding add_chars cell.column.right_border end
print_cells(row)
click to toggle source
# File lib/plain_text.rb, line 59 def print_cells(row) row.cells_including_empty.each do |cell| print_cell(cell) end end
print_heading_row(row)
click to toggle source
# File lib/plain_text.rb, line 35 def print_heading_row(row) print_cells(row) add_new_line underline empty end
print_regular_row(row)
click to toggle source
# File lib/plain_text.rb, line 54 def print_regular_row(row) print_cells(row) add_new_line end
print_row(row)
click to toggle source
# File lib/plain_text.rb, line 23 def print_row(row) if row.heading print_heading_row(row) elsif row.subheading print_subheading_row(row) elsif row.section_end print_section_end_row(row) else print_regular_row(row) end end
print_section_end_row(row)
click to toggle source
# File lib/plain_text.rb, line 48 def print_section_end_row(row) print_cells(row) add_new_line empty end
print_subheading_row(row)
click to toggle source
# File lib/plain_text.rb, line 42 def print_subheading_row(row) print_cells(row) add_new_line empty end
underline()
click to toggle source
# File lib/plain_text.rb, line 73 def underline table.columns.map do |column| char = '-' add_chars column.left_border add_chars column.left_padding_char(char) add_chars char * column.width add_chars column.right_padding_char(char) add_chars column.right_border end add_new_line end