Class: CSVPlusPlus::Language::Scope
- Inherits:
-
Object
- Object
- CSVPlusPlus::Language::Scope
- Defined in:
- lib/csv_plus_plus/language/scope.rb
Overview
A class representing the scope of the current Template and responsible for resolving variables rubocop:disable Metrics/ClassLength
Instance Attribute Summary collapse
-
#code_section ⇒ Object
Returns the value of attribute code_section.
-
#runtime ⇒ Object
readonly
Returns the value of attribute runtime.
Instance Method Summary collapse
-
#initialize(runtime:, code_section: nil) ⇒ Scope
constructor
initialize with a
Runtime
and optionalCodeSection
. -
#resolve_cell_value ⇒ Object
Resolve all values in the ast of the current cell being processed.
-
#to_s ⇒ Object
to_s.
Constructor Details
#initialize(runtime:, code_section: nil) ⇒ Scope
initialize with a Runtime
and optional CodeSection
37 38 39 40 |
# File 'lib/csv_plus_plus/language/scope.rb', line 37 def initialize(runtime:, code_section: nil) @code_section = code_section if code_section @runtime = runtime end |
Instance Attribute Details
#code_section ⇒ Object
Returns the value of attribute code_section.
34 35 36 |
# File 'lib/csv_plus_plus/language/scope.rb', line 34 def code_section @code_section end |
#runtime ⇒ Object (readonly)
Returns the value of attribute runtime.
34 35 36 |
# File 'lib/csv_plus_plus/language/scope.rb', line 34 def runtime @runtime end |
Instance Method Details
#resolve_cell_value ⇒ Object
Resolve all values in the ast of the current cell being processed
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/csv_plus_plus/language/scope.rb', line 43 def resolve_cell_value return unless (ast = @runtime.cell&.ast) last_round = nil loop do refs = ::CSVPlusPlus::Language::References.extract(ast, @code_section) return ast if refs.empty? # TODO: throw an error here instead I think - basically we did a round and didn't make progress return ast if last_round == refs ast = resolve_functions(resolve_variables(ast, refs.variables), refs.functions) end end |
#to_s ⇒ Object
to_s
67 68 69 |
# File 'lib/csv_plus_plus/language/scope.rb', line 67 def to_s "Scope(code_section: #{@code_section}, runtime: #{@runtime})" end |