module TablePal class PlainTextColoured attr_reader :table def initialize(table:) @table = table table.rows.each do |row| print_row(row) end end private 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 def print_heading_row(row) print_cells(row) puts underline empty end def print_subheading_row(row) print_cells(row) puts empty end def print_section_end_row(row) print_cells(row) puts empty end def print_regular_row(row) print_cells(row) puts end def print_cells(row) row.cells_including_empty.each do |cell| print_cell(cell) end end def print_cell(cell) print cell.column.left_border print cell.column.left_padding print cell.formatted(justified: true, coloured: true) print cell.column.right_padding print cell.column.right_border end def underline table.columns.map do |column| char = '-' print column.left_border print column.left_padding_char(char) print char * column.width print column.right_padding_char(char) print column.right_border end puts end def empty table.columns.map do |column| char = ' ' print column.left_border print column.left_padding_char(char) print char * column.width print column.right_padding_char(char) print column.right_border end puts end end end