Class: CSVPlusPlus::Cell
- Inherits:
-
Object
- Object
- CSVPlusPlus::Cell
- Extended by:
- T::Sig
- Defined in:
- lib/csv_plus_plus/cell.rb
Overview
A cell of a template
Instance Attribute Summary collapse
-
#ast ⇒ Entity
The current value of ast.
-
#index ⇒ Integer
readonly
The cell’s index (starts at 0).
-
#modifier ⇒ Modifier
readonly
The modifier for this cell.
-
#row_index ⇒ Integer
The cell’s row index (starts at 0).
Class Method Summary collapse
-
.parse(value, runtime:, modifier:) ⇒ Cell
Parse a
valueinto a Cell object.
Instance Method Summary collapse
-
#evaluate(runtime) ⇒ ::String
A compiled final representation of the cell.
-
#initialize(index:, modifier:, row_index:, value:) ⇒ Cell
constructor
A new instance of Cell.
-
#value ⇒ ::String
The @value (cleaned up some).
Constructor Details
#initialize(index:, modifier:, row_index:, value:) ⇒ Cell
Returns a new instance of Cell.
58 59 60 61 62 63 |
# File 'lib/csv_plus_plus/cell.rb', line 58 def initialize(index:, modifier:, row_index:, value:) @value = value @modifier = modifier @index = index @row_index = row_index end |
Instance Attribute Details
#ast ⇒ Entity
Returns the current value of ast.
11 12 13 |
# File 'lib/csv_plus_plus/cell.rb', line 11 def ast @ast end |
#index ⇒ Integer (readonly)
The cell’s index (starts at 0)
11 12 13 |
# File 'lib/csv_plus_plus/cell.rb', line 11 def index @index end |
#modifier ⇒ Modifier (readonly)
The modifier for this cell
11 12 13 |
# File 'lib/csv_plus_plus/cell.rb', line 11 def modifier @modifier end |
#row_index ⇒ Integer
The cell’s row index (starts at 0)
11 12 13 |
# File 'lib/csv_plus_plus/cell.rb', line 11 def row_index @row_index end |
Class Method Details
.parse(value, runtime:, modifier:) ⇒ Cell
Parse a value into a Cell object.
40 41 42 43 44 |
# File 'lib/csv_plus_plus/cell.rb', line 40 def self.parse(value, runtime:, modifier:) new(value:, row_index: runtime.row_index, index: runtime.cell_index, modifier:).tap do |c| c.ast = ::T.unsafe(::CSVPlusPlus::Parser::CellValue.new).parse(value, runtime) end end |
Instance Method Details
#evaluate(runtime) ⇒ ::String
A compiled final representation of the cell. This can only happen after all cell have had variables and functions resolved.
83 84 85 86 87 |
# File 'lib/csv_plus_plus/cell.rb', line 83 def evaluate(runtime) return value unless @ast "=#{@ast.evaluate(runtime)}" end |
#value ⇒ ::String
The @value (cleaned up some)
TODO: is this used?
70 71 72 73 74 |
# File 'lib/csv_plus_plus/cell.rb', line 70 def value stripped = @value&.strip stripped&.empty? ? nil : stripped end |