class Hollerith::FunctionRunner
Attributes
user_context_change[R]
Public Class Methods
new(declaration, main_context, user_context, user_defined_functions)
click to toggle source
# 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
Public Instance Methods
evaluate()
click to toggle source
# 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
Private Instance Methods
get_arguments_from_declaration()
click to toggle source
# File lib/hollerith/function_runner.rb, line 58 def get_arguments_from_declaration Hollerith::ArgumentDecoder.decode_argument(@declaration) end
get_value(value_to_get, local_context = {})
click to toggle source
# File lib/hollerith/function_runner.rb, line 42 def get_value value_to_get, local_context = {} getter = Hollerith::ValueGetter.new( @main_context, @user_context, @user_defined_functions, @user_context_change, local_context ) return_value = getter.get(value_to_get) @user_context_change.merge!(getter.user_context_change || {}) return_value end