Class: CloudRailSi::ServiceCode::Split

Inherits:
Object
  • Object
show all
Defined in:
lib/cloudrail_si/servicecode/commands/string/Split.rb

Instance Method Summary collapse

Instance Method Details

#execute(environment, parameters) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/cloudrail_si/servicecode/commands/string/Split.rb', line 10

def execute(environment, parameters)
    Helper.assert((parameters.length === 3 || parameters.length === 4) &&
                   Helper.is_var_address(parameters[0]))
    result_var = parameters[0]
    source_string = Helper.resolve(environment, parameters[1])

    Helper.assert(Helper.is_string(source_string))
    separator = Helper.resolve(environment, parameters[2])
    Helper.assert(Helper.is_string(separator))
    limit = 0
    if (parameters.length === 4)
        limit = Helper.resolve(environment, parameters[3])
        Helper.assert(Helper.is_number(limit))
    end
    res = source_string.split(Regexp.new(separator))[0..limit - 1]
    environment.set_variable(result_var, res)
end

#get_identifierObject



6
7
8
# File 'lib/cloudrail_si/servicecode/commands/string/Split.rb', line 6

def get_identifier
    'string.split'
end