class TableGen::Column

Instances of this class are created automatically by {TableGen#column TableGen#column}.

Attributes

alignment[RW]

The alignment of the row fields. Possible values:

  • :left

  • :center

  • :right

(Defaults to :left)

@return [Symbol] @see header_alignment

collapse[RW]

Whether the column can be hidden to respect the table's width constraint. (Defaults to false)

@return [Boolean]

format[RW]

The row formatter. The default block converts the original data to a {String}.

@example Progress Bar

# formats 0.4 to [####      ]
column.format = proc {|fraction, width_hint|
  fill_width = width_hint - 2 # bar borders
  repeat = fraction * fill_width
  "[%-#{fill_width}s]" % ['#' * repeat]
}
# works best with:
column.min_width = 12
column.stretch = true

@param [Object] data whatever you passed to {TableGen#row} @param [Fixnum] width_hint @return [Proc]

header_alignment[RW]

The alignment of the header fields. Possible values:

  • :auto (row alignment)

  • :left

  • :center

  • :right

(Defaults to :auto)

@return [Symbol]

@see alignment

index[R]

The column's index.

@return [Fixnum]

min_width[RW]

The column's minimum width (in characters). (Defaults to 0)

@return [Fixnum]

padding[RW]

The field padding character. (Defaults to a space)

@return [String]

stretch[RW]

Whether to stretch the column to fill the table's width constraint. (Defaults to false)

@return [Boolean]

Public Class Methods

new(index) click to toggle source

@api private

# File lib/tablegen/column.rb, line 76
def initialize(index)
  @index = index

  @alignment = :left
  @collapse = false
  @format = proc {|data| data.to_s }
  @header_alignment = :auto
  @min_width = 0
  @padding = "\x20"
  @stretch = false
end