Class Ruport::Formatter::Text
In: lib/ruport/formatter/text.rb
Parent: Formatter

This class provides text output for Ruport‘s Row, Table, Group, and Grouping renderers

It handles things like automatically truncating tables that go off the edge of the screen in the console, proper column alignment, and pretty output that looks something like this:

  +------------------------------+
  | apple | banana | strawberry  |
  +------------------------------+
  | yes   | no     | yes         |
  | yes   | yes    | red snapper |
  | what  | the    | red snapper |
  +------------------------------+

Supported Options

:max_col_width: Ordinal array of column widths. Set automatically but can be overridden.

:alignment: Defaults to left justify text and right justify numbers. Centers all fields when set to :center.

:table_width: Will truncate rows at this limit.

:show_table_headers: Defaults to true

:show_group_headers: Defaults to true

:ignore_table_width: When set to true, outputs full table without truncating it. Useful for file output.

Methods

Public Instance methods

Hook for setting available options using a template. See the template documentation for the available options and their format.

Creates the group body. Since group data is a table, just uses the Table renderer.

Renders the header for a group using the group name.

Generates the body for a grouping. Iterates through the groups and renders them using the group renderer.

Generates a formatted text row.

Defaults to numeric values being right justified, and other values being left justified. Can be changed to support centering of output by setting options.alignment to :center

Uses fit_to_width to truncate the row if necessary.

Generates the body of the text table.

Defaults to numeric values being right justified, and other values being left justified. Can be changed to support centering of output by setting options.alignment to :center

Uses fit_to_width to truncate the table if necessary.

Uses the column names from the given Data::Table to generate a table header.

Calls fit_to_width to truncate the table heading if necessary.

Determines the text widths for each column.

Truncates a string so that it does not exceed Text#width

Generates the horizontal rule by calculating the total table width and then generating a bar that looks like this:

  "+------------------+"

Used to calculate the max_col_widths array. Override this to tweak the automatic column size adjustments.

Checks to ensure the table is not empty and then calls calculate_max_col_widths.

Returns false if column_names are empty or options.show_table_headers is false/nil. Returns true otherwise.

Returns options.table_width if specified.

Otherwise, uses SystemExtensions to determine terminal width.

[Validate]