Class: TableGen::Column

Inherits:
Object
  • Object
show all
Defined in:
lib/tablegen/column.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(index) ⇒ Column

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Column.



76
77
78
79
80
81
82
83
84
85
86
# 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

Instance Attribute Details

#alignmentSymbol

The alignment of the row fields. Possible values:

  • :left

  • :center

  • :right

(Defaults to :left)

Returns:

  • (Symbol)

See Also:



18
19
20
# File 'lib/tablegen/column.rb', line 18

def alignment
  @alignment
end

#collapseBoolean

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

Returns:

  • (Boolean)


24
25
26
# File 'lib/tablegen/column.rb', line 24

def collapse
  @collapse
end

#formatProc

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

Examples:

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

Parameters:

  • data (Object)

    whatever you passed to TableGen#row

  • width_hint (Fixnum)

Returns:

  • (Proc)


42
43
44
# File 'lib/tablegen/column.rb', line 42

def format
  @format
end

#header_alignmentSymbol

The alignment of the header fields. Possible values:

  • :auto (row alignment)

  • :left

  • :center

  • :right

(Defaults to :auto)

Returns:

  • (Symbol)

See Also:



55
56
57
# File 'lib/tablegen/column.rb', line 55

def header_alignment
  @header_alignment
end

#indexFixnum (readonly)

The column’s index.

Returns:

  • (Fixnum)


6
7
8
# File 'lib/tablegen/column.rb', line 6

def index
  @index
end

#min_widthFixnum

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

Returns:

  • (Fixnum)


61
62
63
# File 'lib/tablegen/column.rb', line 61

def min_width
  @min_width
end

#paddingString

The field padding character. (Defaults to a space)

Returns:

  • (String)


67
68
69
# File 'lib/tablegen/column.rb', line 67

def padding
  @padding
end

#stretchBoolean

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

Returns:

  • (Boolean)


73
74
75
# File 'lib/tablegen/column.rb', line 73

def stretch
  @stretch
end