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, params) ⇒ Cell

Returns a new instance of Cell.



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/terminal-table/cell.rb', line 8

def initialize width, params
  @width = width
  @alignment = :left
  @colspan = 1

  if params.is_a? Hash
    @value = params[:value]
    @alignment = params[:alignment] unless params[:alignment].nil?
    @colspan = params[:colspan] unless params[:colspan].nil?
  else
    @value = params
  end
end

Instance Attribute Details

#alignmentObject

Returns the value of attribute alignment.



6
7
8
# File 'lib/terminal-table/cell.rb', line 6

def alignment
  @alignment
end

#colspanObject

Returns the value of attribute colspan.



6
7
8
# File 'lib/terminal-table/cell.rb', line 6

def colspan
  @colspan
end

#valueObject

Returns the value of attribute value.



6
7
8
# File 'lib/terminal-table/cell.rb', line 6

def value
  @value
end

Instance Method Details

#lengthObject



27
28
29
# File 'lib/terminal-table/cell.rb', line 27

def length
  @value.to_s.length + 2
end

#renderObject Also known as: to_s



22
23
24
# File 'lib/terminal-table/cell.rb', line 22

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