Class: Clin::Text::TableCell
- Inherits:
-
Object
- Object
- Clin::Text::TableCell
- Defined in:
- lib/clin/text/table.rb
Overview
Table cell container class
Instance Method Summary collapse
-
#align ⇒ Symbol
Get the alignment for this cell Can be: * :left * :center * :right.
- #blank? ⇒ Boolean
-
#initialize(table, index, value) ⇒ TableCell
constructor
A new instance of TableCell.
-
#length ⇒ Integer
Get the length of the cell.
-
#to_s ⇒ String
Convert the cell to_s using the length of the column and the column alignment.
Constructor Details
#initialize(table, index, value) ⇒ TableCell
Returns a new instance of TableCell.
226 227 228 229 230 231 |
# File 'lib/clin/text/table.rb', line 226 def initialize(table, index, value) @table = table @index = index @value = value.to_s @table.update_column_length(index, @value.length) end |
Instance Method Details
#align ⇒ Symbol
Get the alignment for this cell Can be:
-
:left
-
:center
-
:right
249 250 251 252 253 |
# File 'lib/clin/text/table.rb', line 249 def align return @table.align if @table.align.is_a? Symbol fail Clin::Error, 'Align must either be a symbol or an Array!' unless @table.align.is_a? Array @table.align[@index] end |
#blank? ⇒ Boolean
239 240 241 |
# File 'lib/clin/text/table.rb', line 239 def blank? @value.blank? end |
#length ⇒ Integer
Get the length of the cell
235 236 237 |
# File 'lib/clin/text/table.rb', line 235 def length @table.column_length[@index] end |
#to_s ⇒ String
Convert the cell to_s using the length of the column and the column alignment
257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/clin/text/table.rb', line 257 def to_s case align when :left @value.to_s.ljust(length) when :right @value.to_s.rjust(length) when :center @value.to_s.center(length) else fail Clin::Error, "Invalid align #{align}" end end |