Class: Terminal::Table::Cell
Direct Known Subclasses
Instance Attribute Summary collapse
-
#alignment ⇒ Object
readonly
Cell alignment.
-
#colspan ⇒ Object
readonly
Column span.
-
#value ⇒ Object
readonly
Cell value.
-
#width ⇒ Object
readonly
Cell width.
Instance Method Summary collapse
-
#initialize(width, options = nil) ⇒ Cell
constructor
Initialize with width and options.
-
#length ⇒ Object
Cell length.
-
#render ⇒ Object
(also: #to_s)
Render the cell.
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, = nil @width = width @value, = , {} unless Hash === @value = .fetch :value, value @alignment = .fetch :alignment, :left @colspan = .fetch :colspan, 1 end |
Instance Attribute Details
#alignment ⇒ Object (readonly)
Cell alignment.
19 20 21 |
# File 'lib/terminal-table/cell.rb', line 19 def alignment @alignment end |
#colspan ⇒ Object (readonly)
Column span.
24 25 26 |
# File 'lib/terminal-table/cell.rb', line 24 def colspan @colspan end |
#value ⇒ Object (readonly)
Cell value.
14 15 16 |
# File 'lib/terminal-table/cell.rb', line 14 def value @value end |
#width ⇒ Object (readonly)
Cell width.
9 10 11 |
# File 'lib/terminal-table/cell.rb', line 9 def width @width end |
Instance Method Details
#length ⇒ Object
Cell length.
48 49 50 |
# File 'lib/terminal-table/cell.rb', line 48 def length value.to_s.length + 2 end |
#render ⇒ Object 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 |