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
# File lib/terminal-table/cell.rb, line 38 def alignment @alignment || :left end
# 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
# File lib/terminal-table/cell.rb, line 34 def alignment? !@alignment.nil? end
# File lib/terminal-table/cell.rb, line 51 def lines @value.to_s.split(/\n/) end
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
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
Generated with the Darkfish Rdoc Generator 2.