Class: ANSI::Columns

### Home Classes Methods

### In Files

- lib/ansi/columns.rb

### Parent

Object

### Methods

- ::new
- #align=
- #columns=
- #format=
- #inspect
- #join
- #list=
- #padding=
- #to_s

### Files

- COPYING.rdoc
- DEMO.rdoc
- HISTORY.rdoc
- README.rdoc

### Class/Module Index

Quicksearch

- ANSI
- ANSI::BBCode
- ANSI::Chain
- ANSI::Code
- ANSI::Columns
- ANSI::Constants
- ANSI::Diff
- ANSI::HexDump
- ANSI::Logger
- ANSI::Mixin
- ANSI::ProgressBar
- ANSI::String
- ANSI::Table
- ANSI::Terminal
- Object
- String

No matching classes.

# ANSI::Columns

### Attributes

align[R]

Alignment to apply to cells.

columns[R]

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

format[R]

Formating to apply to cells.

list[R]

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

padding[R]

Padding size to apply to cells.

### Public Class Methods

new(list, options={}, &format) click to toggle source

Create a column-based layout.

@param [String,Array] list

    Multiline String or Array of strings to columnize.

@param [Hash] options

    Options to customize columnization.

@option options [Fixnum] :columns

    Number of columns.

@option options [Symbol] :align

    Column alignment, either :left, :right or :center.

@option options [String,Fixnum] :padding

    String or number or spaces to append to each column.

The `format` block MUST return ANSI codes.

    # File lib/ansi/columns.rb, line 27
    def initialize(list, options={}, &format)
      self.list = list

      self.columns = options[:columns] || options[:cols]
      self.padding = options[:padding] || 1
      self.align   = options[:align]   || :left
      #self.ansi    = options[:ansi]
      self.format  = format

      #@columns = nil if @columns == 0
    end

### Public Instance Methods

align=(symbol) click to toggle source

Set alignment ensuring value is a symbol.

@param [to_sym] symbol

    Either `:right`, `:left` or `:center`.

@return [Symbol] The given symbol.

    # File lib/ansi/columns.rb, line 91
    def align=(symbol)
      symbol = symbol.to_sym
      raise ArgumentError, "invalid alignment -- #{symbol.inspect}"              unless [:left, :right, :center].include?(symbol)
      @align = symbol
    end

columns=(integer) click to toggle source

Set column count ensuring value is either an integer or nil. The the value given is zero, it will be taken to mean the same as nil, which means fit-to-screen.

    # File lib/ansi/columns.rb, line 64
    def columns=(integer)
      integer = integer.to_i
      @columns = (integer.zero? ? nil : integer)
    end

format=(procedure) click to toggle source

Set formatting procedure. The procedure must return ANSI codes, suitable for passing to String#ansi method.

    # File lib/ansi/columns.rb, line 103
    def format=(procedure)
      @format = procedure ? procedure.to_proc : nil
    end

inspect() click to toggle source

    # File lib/ansi/columns.rb, line 40
    def inspect
      "#<#{self.class}:#{object_id} #{list.inspect} x #{columns}>"
    end

join(cols=nil) click to toggle source

    # File lib/ansi/columns.rb, line 117
    def join(cols=nil)
      to_s_columns(cols || columns)
    end

list=(list) click to toggle source

    # File lib/ansi/columns.rb, line 48
    def list=(list)
      case list
      when ::String
        @list = list.lines.to_a.map{ |e| e.chomp("\n") }
      when ::Array
        @list = list.map{ |e| e.to_s }
      end
    end

padding=(pad) click to toggle source

Set padding to string or number (of spaces).

    # File lib/ansi/columns.rb, line 73
    def padding=(pad)
      case pad
      when Numeric
        @padding = ' ' * pad.to_i
      else
        @padding = pad.to_s
      end
    end

to_s(cols=nil) click to toggle source

Return string in column layout. The number of columns is determined by the `columns` property or overriden by `cols` argument.

    # File lib/ansi/columns.rb, line 112
    def to_s(cols=nil)
      to_s_columns(cols || columns)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.