Sha256: 4b1685c0227bfdb2001f92dda81c591e0982a147a6ab821e72aee3ccf96416ba

Contents?: true

Size: 1.52 KB

Versions: 16

Compression:

Stored size: 1.52 KB

Contents

# frozen_string_literal: true

module FatTable
  # Output the table as plain text. This is almost identical to OrgFormatter
  # except that dates do not get formatted as inactive timestamps and the
  # connector at the beginning of hlines is a '+' rather than a '|' as for org
  # tables.
  class TextFormatter < Formatter
    private

    # Does this Formatter require a second pass over the cells to align the
    # columns according to the alignment formatting instruction to the width of
    # the widest cell in each column?
    def aligned?
      true
    end

    def pre_header(widths)
      result = +'+'
      widths.each_value do |w|
        result += '=' * (w + 2) + '+'
      end
      result[-1] = '+'
      result + "\n"
    end

    def pre_row
      '|'
    end

    def pre_cell(_head)
      ''
    end

    def quote_cell(val)
      val
    end

    def post_cell
      ''
    end

    def inter_cell
      '|'
    end

    def post_row
      "|\n"
    end

    def hline(widths)
      result = +'+'
      widths.each_value do |w|
        result += '-' * (w + 2) + '+'
      end
      result[-1] = '+'
      result + "\n"
    end

    def pre_group
      ''
    end

    def post_group
      ''
    end

    def pre_gfoot
      ''
    end

    def post_gfoot
      ''
    end

    def pre_foot
      ''
    end

    def post_foot
      ''
    end

    def post_footers(widths)
      result = +'+'
      widths.each_value do |w|
        result += '=' * (w + 2) + '+'
      end
      result[-1] = '+'
      result + "\n"
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
fat_table-0.9.8 lib/fat_table/formatters/text_formatter.rb
fat_table-0.9.7 lib/fat_table/formatters/text_formatter.rb
fat_table-0.9.5 lib/fat_table/formatters/text_formatter.rb
fat_table-0.9.3 lib/fat_table/formatters/text_formatter.rb
fat_table-0.9.2 lib/fat_table/formatters/text_formatter.rb
fat_table-0.9.1 lib/fat_table/formatters/text_formatter.rb
fat_table-0.9.0 lib/fat_table/formatters/text_formatter.rb
fat_table-0.8.0 lib/fat_table/formatters/text_formatter.rb
fat_table-0.7.0 lib/fat_table/formatters/text_formatter.rb
fat_table-0.6.6 lib/fat_table/formatters/text_formatter.rb
fat_table-0.6.4 lib/fat_table/formatters/text_formatter.rb
fat_table-0.6.3 lib/fat_table/formatters/text_formatter.rb
fat_table-0.6.2 lib/fat_table/formatters/text_formatter.rb
fat_table-0.6.1 lib/fat_table/formatters/text_formatter.rb
fat_table-0.6.0 lib/fat_table/formatters/text_formatter.rb
fat_table-0.5.5 lib/fat_table/formatters/text_formatter.rb