Class: Hollerith::FunctionRunner

Inherits:
SystemFunctions show all
Defined in:
lib/hollerith/function_runner.rb

Constant Summary

Constants inherited from SystemFunctions

SystemFunctions::BASE_VALID_FUNCTIONS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from SystemFunctions

#__add, #__and, #__array_push, #__array_value, #__blank_array, #__concat, #__count, #__custom_function, #__divide, #__eql, #__for_each, #__if, #__make_external_request, #__multiply, #__negate, #__or, #__puts, #__set, #__split, #__subtract, #custom_system_functions, #valid_functions

Constructor Details

#initialize(declaration, main_context, user_context, user_defined_functions) ⇒ FunctionRunner

Returns a new instance of FunctionRunner.



8
9
10
11
12
13
14
# File 'lib/hollerith/function_runner.rb', line 8

def initialize declaration, main_context, user_context, user_defined_functions
  @declaration = declaration
  @main_context = main_context
  @user_context = user_context
  @user_context_change = {}
  @user_defined_functions = user_defined_functions
end

Instance Attribute Details

#user_context_changeObject (readonly)

Returns the value of attribute user_context_change.



6
7
8
# File 'lib/hollerith/function_runner.rb', line 6

def user_context_change
  @user_context_change
end

Instance Method Details

#evaluateObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/hollerith/function_runner.rb', line 16

def evaluate
  if @declaration.start_with?('%%_')
    function = @declaration[3..-1].split(/,|\(|\)/)

    # This will create a function array
    # '%%_set(result,%%_make_external_request($$_oi))'
    # becomes
    # ["set", "result", "%%_make_external_request", "$$_oi"]
    if valid_functions.include?(function[0])
      arguments_array = get_arguments_from_declaration

      if self.respond_to?("__#{function[0]}", arguments_array)
        send("__#{function[0]}", arguments_array)
      else
        raise ArgumentError.new("#{function[0]} is listed as a valid function but not implemented.")
      end
    else
      raise ArgumentError.new("Undefined function #{function[0]}.")
    end
  else
    raise ArgumentError.new("Exepected function, received #{@declaration}.")
  end
end