class TablePal::Cell
Constants
- JUSTIFICATIONS
Attributes
colour[R]
column[R]
content[R]
formatter[R]
justification[R]
row[R]
Public Class Methods
new(row:, column:, content: '', formatter: nil, justification: nil, colour: nil)
click to toggle source
# File lib/cell.rb, line 14 def initialize(row:, column:, content: '', formatter: nil, justification: nil, colour: nil) @row = row || (raise "Row must be supplied for cell with content: '#{content}' to exist in") @column = column || (raise "Column must be supplied for cell with content: '#{content}' to exist in") @content = content @formatter = formatter || row.formatter || NoFormatting @justification = justification || row.justification || column.justification @colour = colour || row.colour || column.colour || :itself end
Public Instance Methods
colourize(result)
click to toggle source
# File lib/cell.rb, line 41 def colourize(result) result.send(colour) end
format(result)
click to toggle source
# File lib/cell.rb, line 31 def format(result) return '' if result == '' formatter.call(result).to_s end
formatted(justified: false, coloured: false)
click to toggle source
# File lib/cell.rb, line 23 def formatted(justified: false, coloured: false) result = format(content) result = justify(result) if justified result = colourize(result) if coloured result end
justify(result)
click to toggle source
# File lib/cell.rb, line 37 def justify(result) result.send(JUSTIFICATIONS[justification], column.width) end
width()
click to toggle source
# File lib/cell.rb, line 45 def width @width ||= formatted.length end