Class: CSVPlusPlus::Template
- Inherits:
-
Object
- Object
- CSVPlusPlus::Template
- Defined in:
- lib/csv_plus_plus/template.rb
Overview
Contains the data from a parsed csvpp template.
Instance Attribute Summary collapse
-
#rows ⇒ Array<Row>
readonly
The +Row+s that comprise this
Template. -
#scope ⇒ Scope
readonly
The
Scopecontaining all function and variable references.
Instance Method Summary collapse
-
#expand_rows! ⇒ Array<Row>
Apply any expand= modifiers to the parsed template.
-
#initialize(rows:, scope:) ⇒ Template
constructor
A new instance of Template.
- #to_s ⇒ String
-
#validate_infinite_expands(runtime) ⇒ Object
Make sure that the template has a valid amount of infinite expand modifiers.
-
#verbose_summary ⇒ String
Provide a summary of the state of the template (and it's
@scope).
Constructor Details
#initialize(rows:, scope:) ⇒ Template
Returns a new instance of Template.
13 14 15 16 |
# File 'lib/csv_plus_plus/template.rb', line 13 def initialize(rows:, scope:) @scope = scope @rows = rows end |
Instance Attribute Details
#rows ⇒ Array<Row> (readonly)
The +Row+s that comprise this Template
8 9 10 |
# File 'lib/csv_plus_plus/template.rb', line 8 def rows @rows end |
#scope ⇒ Scope (readonly)
The Scope containing all function and variable references
8 9 10 |
# File 'lib/csv_plus_plus/template.rb', line 8 def scope @scope end |
Instance Method Details
#expand_rows! ⇒ Array<Row>
Apply any expand= modifiers to the parsed template
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/csv_plus_plus/template.rb', line 26 def = [] row_index = 0 ( lambda do |new_row| new_row.index = row_index << new_row row_index += 1 end ) @rows = end |
#to_s ⇒ String
19 20 21 |
# File 'lib/csv_plus_plus/template.rb', line 19 def to_s "Template(rows: #{@rows}, scope: #{@scope})" end |
#validate_infinite_expands(runtime) ⇒ Object
Make sure that the template has a valid amount of infinite expand modifiers
43 44 45 46 47 48 49 50 51 |
# File 'lib/csv_plus_plus/template.rb', line 43 def (runtime) = @rows.filter { |r| r.modifier.&.infinite? } return unless .length > 1 runtime.raise_formula_syntax_error( 'You can only have one infinite expand= (on all others you must specify an amount)', [1] ) end |
#verbose_summary ⇒ String
Provide a summary of the state of the template (and it's @scope)
56 57 58 59 60 61 62 63 |
# File 'lib/csv_plus_plus/template.rb', line 56 def verbose_summary # TODO: we can probably include way more stats in here " \#{@scope.verbose_summary}\n\n > \#{@rows.length} rows to be written\n SUMMARY\nend\n" |