Class: Terminal::Table::Cell

Inherits:
Object
  • Object
show all
Defined in:
lib/terminal-table/cell.rb

Direct Known Subclasses

Heading

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(width, options = nil) ⇒ Cell

Initialize with width and options.



29
30
31
32
33
34
35
# File 'lib/terminal-table/cell.rb', line 29

def initialize width, options = nil
  @width = width
  @value, options = options, {} unless Hash === options
  @value = options.fetch :value, value
  @alignment = options.fetch :alignment, :left
  @colspan = options.fetch :colspan, 1
end

Instance Attribute Details

#alignmentObject (readonly)

Cell alignment.



19
20
21
# File 'lib/terminal-table/cell.rb', line 19

def alignment
  @alignment
end

#colspanObject (readonly)

Column span.



24
25
26
# File 'lib/terminal-table/cell.rb', line 24

def colspan
  @colspan
end

#valueObject (readonly)

Cell value.



14
15
16
# File 'lib/terminal-table/cell.rb', line 14

def value
  @value
end

#widthObject (readonly)

Cell width.



9
10
11
# File 'lib/terminal-table/cell.rb', line 9

def width
  @width
end

Instance Method Details

#lengthObject

Cell length.



48
49
50
# File 'lib/terminal-table/cell.rb', line 48

def length
  value.to_s.length + 2
end

#renderObject Also known as: to_s

Render the cell.



40
41
42
# File 'lib/terminal-table/cell.rb', line 40

def render
  " #{value} ".align alignment, width + 2
end