Class: CSVPlusPlus::CodeSection
- Inherits:
-
Object
- Object
- CSVPlusPlus::CodeSection
- Defined in:
- lib/csv_plus_plus/code_section.rb
Overview
A representation of the code section part of a template (the variable and function definitions)
Instance Attribute Summary collapse
-
#functions ⇒ Hash<Symbol, Function>
readonly
All defined functions.
-
#variables ⇒ Hash<Symbol, Variable>
All defined variables.
Instance Method Summary collapse
-
#def_function(id, entity) ⇒ Object
Define a (or re-define an existing) function.
-
#def_variable(id, entity) ⇒ Object
Define a (or re-define an existing) variable.
-
#def_variables(variables) ⇒ Object
Define (or re-define existing) variables.
-
#defined_function?(fn_id) ⇒ boolean
Is the function defined?.
-
#defined_variable?(var_id) ⇒ boolean
Is the variable defined?.
-
#initialize(variables: {}, functions: {}) ⇒ CodeSection
constructor
A new instance of CodeSection.
- #to_s ⇒ String
-
#verbose_summary ⇒ String
Provide a summary of the functions and variables compiled (to show in verbose mode).
Constructor Details
#initialize(variables: {}, functions: {}) ⇒ CodeSection
Returns a new instance of CodeSection.
17 18 19 20 |
# File 'lib/csv_plus_plus/code_section.rb', line 17 def initialize(variables: {}, functions: {}) @variables = variables @functions = functions end |
Instance Attribute Details
#functions ⇒ Hash<Symbol, Function> (readonly)
All defined functions
11 12 13 |
# File 'lib/csv_plus_plus/code_section.rb', line 11 def functions @functions end |
#variables ⇒ Hash<Symbol, Variable>
All defined variables
11 12 13 |
# File 'lib/csv_plus_plus/code_section.rb', line 11 def variables @variables end |
Instance Method Details
#def_function(id, entity) ⇒ Object
Define a (or re-define an existing) function
41 42 43 |
# File 'lib/csv_plus_plus/code_section.rb', line 41 def def_function(id, entity) @functions[id.to_sym] = entity end |
#def_variable(id, entity) ⇒ Object
Define a (or re-define an existing) variable
26 27 28 |
# File 'lib/csv_plus_plus/code_section.rb', line 26 def def_variable(id, entity) @variables[id.to_sym] = entity end |
#def_variables(variables) ⇒ Object
Define (or re-define existing) variables
33 34 35 |
# File 'lib/csv_plus_plus/code_section.rb', line 33 def def_variables(variables) variables.each { |id, entity| def_variable(id, entity) } end |
#defined_function?(fn_id) ⇒ boolean
Is the function defined?
59 60 61 |
# File 'lib/csv_plus_plus/code_section.rb', line 59 def defined_function?(fn_id) @functions.key?(fn_id.to_sym) end |
#defined_variable?(var_id) ⇒ boolean
Is the variable defined?
50 51 52 |
# File 'lib/csv_plus_plus/code_section.rb', line 50 def defined_variable?(var_id) @variables.key?(var_id.to_sym) end |
#to_s ⇒ String
64 65 66 |
# File 'lib/csv_plus_plus/code_section.rb', line 64 def to_s "CodeSection(functions: #{@functions}, variables: #{@variables})" end |
#verbose_summary ⇒ String
Provide a summary of the functions and variables compiled (to show in verbose mode)
71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/csv_plus_plus/code_section.rb', line 71 def verbose_summary <<~SUMMARY # Code Section Summary ## Resolved Variables #{variable_summary} ## Functions #{function_summary} SUMMARY end |