Module: CSVPlusPlus::CanDefineReferences

Included in:
Scope
Defined in:
lib/csv_plus_plus/can_define_references.rb

Overview

Methods for classes that need to manage @variables and @functions

Instance Method Summary collapse

Instance Method Details

#def_function(id, entity) ⇒ Object

Define a (or re-define an existing) function

Parameters:

  • id (String, Symbol)

    The identifier for the function

  • entity (Entities::Function)

    The defined function



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

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

#def_variable(id, entity) ⇒ Object

Define a (or re-define an existing) variable

Parameters:

  • id (String, Symbol)

    The identifier for the variable

  • entity (Entity)

    The value (entity) the variable holds



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

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

#def_variables(vars) ⇒ Object

Define (or re-define existing) variables

Parameters:

  • variables (Hash<Symbol, Variable>)

    Variables to define



17
18
19
# File 'lib/csv_plus_plus/can_define_references.rb', line 17

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

#defined_function?(fn_id) ⇒ boolean

Is the function defined?

Parameters:

  • fn_id (Symbol, String)

    The identifier of the function

Returns:

  • (boolean)


43
44
45
# File 'lib/csv_plus_plus/can_define_references.rb', line 43

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

#defined_variable?(var_id) ⇒ boolean

Is the variable defined?

Parameters:

  • var_id (Symbol, String)

    The identifier of the variable

Returns:

  • (boolean)


34
35
36
# File 'lib/csv_plus_plus/can_define_references.rb', line 34

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

#verbose_summaryString

Provide a summary of the functions and variables compiled (to show in verbose mode)

Returns:

  • (String)


50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/csv_plus_plus/can_define_references.rb', line 50

def verbose_summary
  <<~SUMMARY
    # Code Section Summary

    ## Resolved Variables

    #{variable_summary}

    ## Functions

    #{function_summary}
  SUMMARY
end