lib/openstudio/analysis/formulation.rb in openstudio-analysis-0.4.4 vs lib/openstudio/analysis/formulation.rb in openstudio-analysis-0.4.5

- old
+ new

@@ -151,11 +151,11 @@ } } if @seed_model[:file] h[:analysis][:seed] = { - file_type: File.extname(@seed_model[:file]).gsub('.', '').upcase, + file_type: File.extname(@seed_model[:file]).delete('.').upcase, path: "./seed/#{File.basename(@seed_model[:file])}" } else h[:analysis][:seed] = nil end @@ -169,11 +169,11 @@ wf = @weather_files.find { |w| File.extname(w[:file]).downcase == '.epw' } end if wf h[:analysis][:weather_file] = { - file_type: File.extname(wf[:file]).gsub('.', '').upcase, + file_type: File.extname(wf[:file]).delete('.').upcase, path: "./weather/#{File.basename(wf[:file])}" } else # log: could not find weather file warn 'Could not resolve a valid weather file. Check paths to weather files' @@ -247,34 +247,42 @@ end end # save the file to JSON. Will overwrite the file if it already exists # - # @param filename [String] Name of file to create. It will create the directory and override the file if it exists. + # @param filename [String] Name of file to create. It will create the directory and override the file if it exists. If no file extension is given, then it will use .json. # @param version [Integer] Version of the format to return # @return [Boolean] def save(filename, version = 1) + filename += '.json' if File.extname(filename) == '' + FileUtils.mkdir_p File.dirname(filename) unless Dir.exist? File.dirname(filename) File.open(filename, 'w') { |f| f << JSON.pretty_generate(to_hash(version)) } true end # save the data point JSON with the variables set to the static values. Will overwrite the file if it already exists # + # @param filename [String] Name of file to create. It will create the directory and override the file if it exists. If no file extension is given, then it will use .json. # @param version [Integer] Version of the format to return # @return [Boolean] def save_static_data_point(filename, version = 1) + filename += '.json' if File.extname(filename) == '' + + FileUtils.mkdir_p File.dirname(filename) unless Dir.exist? File.dirname(filename) File.open(filename, 'w') { |f| f << JSON.pretty_generate(to_static_data_point_hash(version)) } true end # save the analysis zip file which contains the measures, seed model, weather file, and init/final scripts # - # @param filename [String] Name of file to create. It will create the directory and override the file if it exists. + # @param filename [String] Name of file to create. It will create the directory and override the file if it exists. If no file extension is given, then it will use .json. # @return [Boolean] def save_zip(filename) + filename += '.zip' if File.extname(filename) == '' + FileUtils.mkdir_p File.dirname(filename) unless Dir.exist? File.dirname(filename) save_analysis_zip(filename) end