Method: JSCompiler.parse_json_output
- Defined in:
- lib/jsc/closure_compiler.rb
.parse_json_output(response) ⇒ Object
Parses and returns JSON server response
Accepted parameters:
-
response: the server response
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/jsc/closure_compiler.rb', line 110 def parse_json_output(response) out = "" parsed_response = ActiveSupport::JSON.decode(response) if parsed_response.has_key?("serverErrors") result = parsed_response['serverErrors'] return "Server Error: #{result[0]['error']} - Error Code: #{result[0]['code']}" end case @op when "compiled_code" out = parsed_response['compiledCode'] when "statistics" result = parsed_response['statistics'] out = create_statistics_output(result) else "errors" #case for errors or warnings begin result = parsed_response[@op] unless result.nil? num = result.size out << "You've got #{result.size} #{@op}\n" i = 0 result.each do || i += 1 out << "\n#{@op.singularize.capitalize} n.#{i}\n" out << "\t#{['type']}: " + [@op.singularize] + " at line #{['lineno']} character #{['charno']}\n" out << "\t" + ['line'] + "\n" unless ['line'].nil? end return out else return "No #{@op}" end rescue out = "Error parsing JSON output...Check your output" end end end |