Class: CSVPlusPlus::CodeSection

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(variables: {}, functions: {}) ⇒ CodeSection

initialize



14
15
16
17
# File 'lib/csv_plus_plus/code_section.rb', line 14

def initialize(variables: {}, functions: {})
  @variables = variables
  @functions = functions
end

Instance Attribute Details

#functionsObject (readonly)

Returns the value of attribute functions.



10
11
12
# File 'lib/csv_plus_plus/code_section.rb', line 10

def functions
  @functions
end

#variablesObject

Returns the value of attribute 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



30
31
32
# File 'lib/csv_plus_plus/code_section.rb', line 30

def def_function(id, entity)
  @functions[id.to_sym] = entity
end

#def_variable(id, entity) ⇒ Object

Define a (or re-define an existing) variable



20
21
22
# File 'lib/csv_plus_plus/code_section.rb', line 20

def def_variable(id, entity)
  @variables[id.to_sym] = entity
end

#def_variables(variables) ⇒ Object

Define (or re-define existing) variables



25
26
27
# File 'lib/csv_plus_plus/code_section.rb', line 25

def def_variables(variables)
  variables.each { |id, entity| def_variable(id, entity) }
end

#defined_function?(fn_id) ⇒ Boolean

Is the function defined?

Returns:

  • (Boolean)


40
41
42
# File 'lib/csv_plus_plus/code_section.rb', line 40

def defined_function?(fn_id)
  @functions.key?(fn_id.to_sym)
end

#defined_variable?(var_id) ⇒ Boolean

Is the variable defined?

Returns:

  • (Boolean)


35
36
37
# File 'lib/csv_plus_plus/code_section.rb', line 35

def defined_variable?(var_id)
  @variables.key?(var_id.to_sym)
end

#to_sObject

to_s



45
46
47
# File 'lib/csv_plus_plus/code_section.rb', line 45

def to_s
  "CodeSection(functions: #{@functions}, variables: #{@variables})"
end