Class: ANSI::Columns
- Inherits:
-
Object
- Object
- ANSI::Columns
- Defined in:
- lib/ansi/columns.rb
Instance Attribute Summary collapse
-
#align ⇒ Object
Alignment to apply to cells.
-
#columns ⇒ Object
Default number of columns to display.
-
#format ⇒ Object
Formating to apply to cells.
-
#list ⇒ Object
List layout into columns.
-
#padding ⇒ Object
Padding size to apply to cells.
Instance Method Summary collapse
-
#initialize(list, options = {}, &format) ⇒ Columns
constructor
Create a column-based layout.
- #inspect ⇒ Object
- #join(cols = nil) ⇒ Object
-
#to_s(cols = nil) ⇒ Object
Return string in column layout.
Constructor Details
#initialize(list, options = {}, &format) ⇒ Columns
Create a column-based layout.
The format block MUST return ANSI codes.
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/ansi/columns.rb', line 26 def initialize(list, ={}, &format) self.list = list self.columns = [:columns] || [:cols] self.padding = [:padding] || 1 self.align = [:align] || :left #self.ansi = options[:ansi] self.format = format #@columns = nil if @columns == 0 end |
Instance Attribute Details
#align ⇒ Object
Alignment to apply to cells.
82 83 84 |
# File 'lib/ansi/columns.rb', line 82 def align @align end |
#columns ⇒ Object
Default number of columns to display. If nil then the number of coumns is estimated from the size of the terminal.
58 59 60 |
# File 'lib/ansi/columns.rb', line 58 def columns @columns end |
#format ⇒ Object
Formating to apply to cells.
98 99 100 |
# File 'lib/ansi/columns.rb', line 98 def format @format end |
#list ⇒ Object
List layout into columns. Each new line is taken to be a row-column cell.
45 46 47 |
# File 'lib/ansi/columns.rb', line 45 def list @list end |
#padding ⇒ Object
Padding size to apply to cells.
69 70 71 |
# File 'lib/ansi/columns.rb', line 69 def padding @padding end |
Instance Method Details
#inspect ⇒ Object
39 40 41 |
# File 'lib/ansi/columns.rb', line 39 def inspect "#<#{self.class}:#{object_id} #{list.inspect} x #{columns}>" end |
#join(cols = nil) ⇒ Object
116 117 118 |
# File 'lib/ansi/columns.rb', line 116 def join(cols=nil) to_s_columns(cols || columns) end |
#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.
111 112 113 |
# File 'lib/ansi/columns.rb', line 111 def to_s(cols=nil) to_s_columns(cols || columns) end |