Class: CloudRailSi::ServiceCode::Parse
- Inherits:
-
Object
- Object
- CloudRailSi::ServiceCode::Parse
- Defined in:
- lib/cloudrail_si/servicecode/commands/json/Parse.rb
Instance Method Summary collapse
Instance Method Details
#execute(environment, parameters) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/cloudrail_si/servicecode/commands/json/Parse.rb', line 11 def execute(environment, parameters) Helper.assert(parameters.length == 2 && Helper.is_var_address(parameters[0])) result_var = parameters[0] input = Helper.resolve(environment, parameters[1]) Helper.assert(Helper.is_stream(input) || Helper.is_string(input)) if (Helper.is_stream(input)) return Helper.dump_stream(input, lambda { |string_input| Helper.assert(Helper.is_string(string_input)) obj = parse(string_input) environment.set_variable(result_var, obj) }) else obj = parse(input) environment.set_variable(result_var, obj) end end |
#get_identifier ⇒ Object
7 8 9 |
# File 'lib/cloudrail_si/servicecode/commands/json/Parse.rb', line 7 def get_identifier return 'json.parse' end |
#parse(input) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/cloudrail_si/servicecode/commands/json/Parse.rb', line 29 def parse(input) parsed = JSON.parse(input) Helper.log("Parsed JSON: #{parsed}\n\n") parsed.each do |key| if Helper.is_boolean(parsed[key]) parsed[key] = parsed[key] ? 1 : 0 #TODO: this needs to work deeply; affects stripe end end end |