Parent

Files

Terminal::Table::Cell

Attributes

colspan[R]

Column span.

value[R]

Cell value.

width[R]

Cell width.

Public Class Methods

new(options = nil) click to toggle source

Initialize with options.

# File lib/terminal-table/cell.rb, line 24
def initialize options = nil
  @value, options = options, {} unless Hash === options
  @value = options.fetch :value, value
  @alignment = options.fetch :alignment, nil
  @colspan = options.fetch :colspan, 1
  @width = options.fetch :width, @value.to_s.size
  @index = options.fetch :index
  @table = options.fetch :table
end

Public Instance Methods

alignment() click to toggle source
# File lib/terminal-table/cell.rb, line 38
def alignment
  @alignment || :left
end
alignment=(val) click to toggle source
# File lib/terminal-table/cell.rb, line 42
def alignment=(val)
  supported = %(left center right)
  if supported.include?(val.to_s)
    @alignment = val
  else
    raise "Aligment must be one of: #{supported.join(' ')}"
  end
end
alignment?() click to toggle source
# File lib/terminal-table/cell.rb, line 34
def alignment?
  !@alignment.nil?
end
lines() click to toggle source
# File lib/terminal-table/cell.rb, line 51
def lines
  @value.to_s.split(/\n/)
end
render(line = 0) click to toggle source

Render the cell.

# File lib/terminal-table/cell.rb, line 58
def render(line = 0)
  left = " " * @table.style.padding_left
  right = " " * @table.style.padding_right
  "#{left}#{lines[line]}#{right}".align(alignment, width + @table.cell_padding)
end
Also aliased as: to_s
to_s(line = 0) click to toggle source
Alias for: render
value_for_column_width_recalc() click to toggle source

Returns the longest line in the cell and removes all ANSI escape sequences (e.g. color)

# File lib/terminal-table/cell.rb, line 69
def value_for_column_width_recalc
  str = lines.sort_by { |s| s.size }.last.to_s
  str = str.gsub(/\x1b(\[|\(|\))[;?0-9]*[0-9A-Za-z]/, '')
  str = str.gsub(/\x1b(\[|\(|\))[;?0-9]*[0-9A-Za-z]/, '')
  str.gsub(/[\x03|\x1a]/, '')
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.