Class: CSVPlusPlus::Cell
- Inherits:
-
Object
- Object
- CSVPlusPlus::Cell
- 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
-
#initialize(row_index:, index:, value:, modifier:) ⇒ Cell
constructor
A new instance of Cell.
-
#to_csv ⇒ String
A compiled final representation of the cell.
- #to_s ⇒ String
-
#value ⇒ String
The @value (cleaned up some).
Constructor Details
#initialize(row_index:, index:, value:, modifier:) ⇒ Cell
Returns a new instance of Cell.
34 35 36 37 38 39 |
# File 'lib/csv_plus_plus/cell.rb', line 34 def initialize(row_index:, index:, value:, modifier:) @value = value @modifier = modifier @index = index @row_index = row_index end |
Instance Attribute Details
#ast ⇒ Entity
Returns the current value of ast.
13 14 15 |
# File 'lib/csv_plus_plus/cell.rb', line 13 def ast @ast end |
#index ⇒ Integer (readonly)
The cell’s index (starts at 0)
13 14 15 |
# File 'lib/csv_plus_plus/cell.rb', line 13 def index @index end |
#modifier ⇒ Modifier (readonly)
The modifier for this cell
13 14 15 |
# File 'lib/csv_plus_plus/cell.rb', line 13 def modifier @modifier end |
#row_index ⇒ Integer
The cell’s row index (starts at 0)
13 14 15 |
# File 'lib/csv_plus_plus/cell.rb', line 13 def row_index @row_index end |
Class Method Details
.parse(value, runtime:, modifier:) ⇒ Cell
Parse a value into a Cell object.
24 25 26 27 28 |
# File 'lib/csv_plus_plus/cell.rb', line 24 def self.parse(value, runtime:, modifier:) new(value:, row_index: runtime.row_index, index: runtime.cell_index, modifier:).tap do |c| c.ast = ::CSVPlusPlus::Parser::CellValue.new.parse(value, runtime) end end |
Instance Method Details
#to_csv ⇒ String
A compiled final representation of the cell. This can only happen after all cell have had variables and functions resolved.
59 60 61 62 63 64 65 |
# File 'lib/csv_plus_plus/cell.rb', line 59 def to_csv return value unless @ast # This looks really simple but we're relying on each node of the AST to define #to_s such that calling # this at the top will recursively print the tree (as a well-formatted spreadsheet formula) "=#{@ast}" end |
#to_s ⇒ String
51 52 53 |
# File 'lib/csv_plus_plus/cell.rb', line 51 def to_s "Cell(index: #{@index}, row_index: #{@row_index}, value: #{@value}, modifier: #{@modifier})" end |
#value ⇒ String
The @value (cleaned up some)
44 45 46 47 48 |
# File 'lib/csv_plus_plus/cell.rb', line 44 def value return if @value.nil? || @value.strip.empty? @value.strip end |