Class: Jekyll::DatabaseTables::Formatter

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll-database-tables/formatters.rb

Overview

Abstract base class for table formatters.

Subclasses must implement #render, #format_row, and #separator. Shared rendering utilities are available via Helpers.

Direct Known Subclasses

PsqlFormatter

Defined Under Namespace

Modules: Helpers

Instance Method Summary collapse

Instance Method Details

#format_row(cells, widths) ⇒ String

Formats a single row of cells into a string

Parameters:

  • cells (Array<#to_s>)

    the cell values to render

  • widths (Array<Integer>)

    the column widths to align against

Returns:

  • (String)

    the formatted row

Raises:

  • (NotImplementedError)

    if the subclass does not implement this method



47
48
49
# File 'lib/jekyll-database-tables/formatters.rb', line 47

def format_row(cells, widths)
  raise NotImplementedError, "#{self.class} must implement #format_row"
end

#render(table, title: nil) ⇒ String

Renders a Table to a string.

Parameters:

  • table (Table)

    the table to render

  • title (String, nil) (defaults to: nil)

    an optional title to display above headers

Returns:

  • (String)

    the rendered output

Raises:

  • (NotImplementedError)

    if the subclass does not implement this method



37
38
39
# File 'lib/jekyll-database-tables/formatters.rb', line 37

def render(table, title: nil)
  raise NotImplementedError, "#{self.class} must implement #render"
end

#separator(widths) ⇒ String

Renders the separator line between headers and data rows.

Parameters:

  • widths (Array<Integer>)

    the column widths to size the separator against

Returns:

  • (String)

    the separator line

Raises:

  • (NotImplementedError)

    if the subclass does not implement this method



56
57
58
# File 'lib/jekyll-database-tables/formatters.rb', line 56

def separator(widths)
  raise NotImplementedError, "#{self.class} must implement #separator"
end