Class: CloudRailSi::ServiceCode::MathCombine

Inherits:
Object
  • Object
show all
Defined in:
lib/cloudrail_si/servicecode/commands/math/MathCombine.rb

Instance Method Summary collapse

Constructor Details

#initialize(identifier, combine_function) ⇒ MathCombine

Returns a new instance of MathCombine.



6
7
8
9
# File 'lib/cloudrail_si/servicecode/commands/math/MathCombine.rb', line 6

def initialize(identifier, combine_function)
    @identifier = identifier
    @combine_function = combine_function
end

Instance Method Details

#execute(environment, parameters) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/cloudrail_si/servicecode/commands/math/MathCombine.rb', line 15

def execute(environment, parameters)
    Helper.assert(parameters.length >= 2 &&
                  Helper.is_var_address(parameters[0]))
    result_var = parameters[0]
    elements = []

    (1..(parameters.length - 1)).each do |i|
        resolved = Helper.resolve(environment, parameters[i])
        resolved = resolved.to_f if (Helper.is_string(resolved) && resolved.index('.'))
        resolved = resolved.to_i if (Helper.is_string(resolved) && resolved.index('.').nil?)

        Helper.assert(Helper.is_number(resolved))
        elements.push(resolved)
    end

    res = @combine_function.call(elements)
    environment.set_variable(result_var, res)
end

#get_identifierObject



11
12
13
# File 'lib/cloudrail_si/servicecode/commands/math/MathCombine.rb', line 11

def get_identifier
    @identifier
end