class AsciiParadise::AsciiTable::Cell
Attributes
colspan[R]
attr_reader :width # Cell
width.
Public Class Methods
new(options = nil)
click to toggle source
#¶ ↑
initialize¶ ↑
Initialize with options.
#¶ ↑
# File lib/ascii_paradise/asciitable/cell.rb, line 21 def initialize(options = nil) reset @value, options = options, {} unless Hash === options @value = options.fetch :value, value @alignment = options.fetch :alignment, nil @alignment = :center if @alignment == :middle @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
alignment=(i)
click to toggle source
#¶ ↑
alignment=¶ ↑
#¶ ↑
# File lib/ascii_paradise/asciitable/cell.rb, line 50 def alignment=(i) supported_alignments = %w( left center right ) case i when :middle i = :center end if supported_alignments.include?(i.to_s) @alignment = i else raise "Aligment must be one of: #{supported_alignments.join(' ')}" end end
alignment?()
click to toggle source
escape(i)
click to toggle source
lines()
click to toggle source
render(line = 0)
click to toggle source
#¶ ↑
render¶ ↑
Render the cell.
alignment can be :left or :right or :center.
#¶ ↑
# File lib/ascii_paradise/asciitable/cell.rb, line 125 def render(line = 0) left = ' ' * @table.style.padding_left right = ' ' * @table.style.padding_right render_width = lines[line].to_s.size - escape(lines[line]).size + width line = "#{left}#{lines[line]}#{right}" horizontal_length = render_width + @table.cell_padding case alignment when :left line.ljust(horizontal_length) when :right line.rjust(horizontal_length) when :center line.center(horizontal_length) end end
Also aliased as: to_s
reset()
click to toggle source
value?()
click to toggle source
Also aliased as: value
value_for_column_width_recalc()
click to toggle source
width()
click to toggle source