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.
-
#to_s(cols = nil) ⇒ Object
Return string in column layout.
Constructor Details
#initialize(list, options = {}, &format) ⇒ Columns
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/ansi/columns.rb', line 17 def initialize(list, ={}, &format) self.list = list @columns = [:columns] @padding = [:padding] || 1 @align = [:align] #@ansi = [options[:ansi]].flatten @format = format @columns = nil if @columns == 0 end |
Instance Attribute Details
#align ⇒ Object
Alignment to apply to cells.
50 51 52 |
# File 'lib/ansi/columns.rb', line 50 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.
44 45 46 |
# File 'lib/ansi/columns.rb', line 44 def columns @columns end |
#format ⇒ Object
Formating to apply to cells.
53 54 55 |
# File 'lib/ansi/columns.rb', line 53 def format @format end |
#list ⇒ Object
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 |
#padding ⇒ Object
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 |