struct Tablo::Summary::BodyColumn

Overview

The Summary::BodyColumn struct lets you define specific alignment, formatting and styling on body columns.

Defined in:

summary.cr

Constructors

Constructor Detail

def self.new(column : LabelType | Array(LabelType), *, alignment : Justify | Nil = nil, formatter : Cell::Data::Formatter | Nil = nil, styler : Cell::Data::Styler | Nil = nil) #

The constructor expects up to 4 parameters, of which the first, the column identifier, is the only mandatory one (but it goes without saying that at least one of the 3 optional parameters must be defined!)

  • column : Column identifier (or array of column identifiers)

  • The last three optional parameters are alignment, formatter and styler

Example:

Tablo::Summary::BodyColumn.new(:total, alignment: Tablo::Justify::Right,
  formatter: ->(value : Tablo::CellType) {
    value.is_a?(String) ? value : (
      value.nil? ? "" : "%.2f" % value.as(BigDecimal)
    )
  },
  styler: ->(_value : Tablo::CellType, cd : Tablo::Cell::Data::Coords, fc : String) {
    case cd.row_index
    when 0, 2, 5 then fc.colorize.mode(:bold).to_s
    when 1       then fc.colorize.mode(:italic).to_s
    else              fc
    end
  })

[View source]