Sha256: 6452a0a0626f10803bb6ce23dba9dc82f739a1b917d03696b11ddbdddf818efc

Contents?: true

Size: 1.44 KB

Versions: 3

Compression:

Stored size: 1.44 KB

Contents

module FatTable
  # Output the table in the same way as org-mode for emacs does. This is almost
  # identical to TextFormatter except that dates do get formatted as inactive
  # timestamps and the connector at the beginning of hlines is a '|' rather than
  # a '+' as for text tables.
  class OrgFormatter < Formatter
    self.default_format = default_format.dup
    default_format[:date_fmt] = '[%F]'
    default_format[:datetime_fmt] = '[%F %a %H:%M:%S]'

    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 post_footers(widths)
      result = '|'
      widths.each_value do |w|
        result += '-' * (w + 2) + '+'
      end
      result[-1] = '|'
      result + "\n"
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
fat_table-0.3.0 lib/fat_table/formatters/org_formatter.rb
fat_table-0.2.11 lib/fat_table/formatters/org_formatter.rb
fat_table-0.2.9 lib/fat_table/formatters/org_formatter.rb