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 ⇒ Object
Returns the value of attribute ast.
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#modifier ⇒ Object
readonly
Returns the value of attribute modifier.
-
#row_index ⇒ Object
Returns the value of attribute row_index.
Class Method Summary collapse
-
.parse(value, runtime:, modifier:) ⇒ Object
Parse a
value
into a Cell object.
Instance Method Summary collapse
-
#initialize(row_index:, index:, value:, modifier:) ⇒ Cell
constructor
initialize.
-
#to_csv ⇒ Object
A compiled final representation of the cell.
-
#to_s ⇒ Object
to_s.
-
#value ⇒ Object
The value (cleaned up some).
Constructor Details
#initialize(row_index:, index:, value:, modifier:) ⇒ Cell
initialize
22 23 24 25 26 27 |
# File 'lib/csv_plus_plus/cell.rb', line 22 def initialize(row_index:, index:, value:, modifier:) @value = value @modifier = modifier @index = index @row_index = row_index end |
Instance Attribute Details
#ast ⇒ Object
Returns the value of attribute ast.
10 11 12 |
# File 'lib/csv_plus_plus/cell.rb', line 10 def ast @ast end |
#index ⇒ Object (readonly)
Returns the value of attribute index.
11 12 13 |
# File 'lib/csv_plus_plus/cell.rb', line 11 def index @index end |
#modifier ⇒ Object (readonly)
Returns the value of attribute modifier.
11 12 13 |
# File 'lib/csv_plus_plus/cell.rb', line 11 def modifier @modifier end |
#row_index ⇒ Object
Returns the value of attribute row_index.
10 11 12 |
# File 'lib/csv_plus_plus/cell.rb', line 10 def row_index @row_index end |
Class Method Details
.parse(value, runtime:, modifier:) ⇒ Object
Parse a value
into a Cell object. The value
should already have been through a CSV parser
15 16 17 18 19 |
# File 'lib/csv_plus_plus/cell.rb', line 15 def self.parse(value, runtime:, modifier:) new(value:, row_index: runtime.row_index, index: runtime.cell_index, modifier:).tap do |c| c.ast = ::CSVPlusPlus::Language::CellValueParser.new.parse(value, runtime) end end |
Instance Method Details
#to_csv ⇒ Object
A compiled final representation of the cell. This can only happen after all cell have had variables and functions resolved.
43 44 45 46 47 48 49 |
# File 'lib/csv_plus_plus/cell.rb', line 43 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 and calling # this at the top will recursively print the tree "=#{@ast}" end |
#to_s ⇒ Object
to_s
37 38 39 |
# File 'lib/csv_plus_plus/cell.rb', line 37 def to_s "Cell(index: #{@index}, row_index: #{@row_index}, value: #{@value}, modifier: #{@modifier})" end |
#value ⇒ Object
The value (cleaned up some)
30 31 32 33 34 |
# File 'lib/csv_plus_plus/cell.rb', line 30 def value return if @value.nil? || @value.strip.empty? @value.strip end |