Class: ANSI::Columns

Inherits:
Object
  • Object
show all
Defined in:
lib/ansi/columns.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(list, options = {}, &format) ⇒ Columns

Create a column-based layout.

list - Multiline String or Array of strings to columnize

options - number of columns options - align :left or :right options - space to add to each cell

The format block MUST return ANSI codes.



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/ansi/columns.rb', line 17

def initialize(list, options={}, &format)
  self.list = list

  @columns = options[:columns]
  @padding = options[:padding] || 1
  @align   = options[:align]
  #@ansi    = [options[:ansi]].flatten
  @format  = format

  @columns = nil if @columns == 0
end

Instance Attribute Details

#alignObject

Alignment to apply to cells.



50
51
52
# File 'lib/ansi/columns.rb', line 50

def align
  @align
end

#columnsObject

Default number of columns to display. If nil then the number of coumns is estimated from the size of the terminal.



44
45
46
# File 'lib/ansi/columns.rb', line 44

def columns
  @columns
end

#formatObject

Formating to apply to cells.



53
54
55
# File 'lib/ansi/columns.rb', line 53

def format
  @format
end

#listObject

List layout into columns. Each new line is taken to be a row-column cell.



31
32
33
# File 'lib/ansi/columns.rb', line 31

def list
  @list
end

#paddingObject

Padding size to apply to cells.



47
48
49
# File 'lib/ansi/columns.rb', line 47

def padding
  @padding
end

Instance Method Details

#to_s(cols = nil) ⇒ Object

Return string in column layout. The number of columns is determined by the ‘columns` property or overriden by cols argument. – TODO: Allow #to_s to take options and formating block? ++



60
61
62
# File 'lib/ansi/columns.rb', line 60

def to_s(cols=nil)
  to_s_columns(cols || columns)
end