Sha256: f183a9bd5527018de3a165de65616fe10fcdf1ff8bc91af78549f2539e1bf79b

Contents?: true

Size: 1.11 KB

Versions: 21

Compression:

Stored size: 1.11 KB

Contents

# This utility adds a template field defining the NECB data the given json file refers to.  The template field is added
# to the top of each element in the table array.

require 'json'

class Add_template_field_to_json
  # Name of file you want to add template fields to:
  in_json_file = './necb_hvac_system_selection_type.json'
  # Name of file you want this script to produce:
  out_json_file = './necb_hvac_system_selection_type_mod.json'
  # What template version do you want to add:
  template_version = {"template" => "NECB2011"}
  # Open the json file and put the data in data_tables:
  file = File.read(in_json_file)
  data_tables = JSON.parse(file)
  # Go through the file and add whatever you put in template_version to the top of each element of the table array
  data_tables['tables'][0]['table'].each_with_index do |data_table, index|
    data_tables['tables'][0]['table'][index] = template_version.merge(data_table)
  end
  # Save the modified hash to a the file and location defined in out_json_file
  File.open(out_json_file,"w") { |each_file| each_file.write(JSON.pretty_generate(data_tables)) }
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
openstudio-standards-0.2.3 lib/openstudio-standards/utilities/Add_template_field_to_json.rb