module BTAP::Common
This contains methods for creation and querying object that deal with Envelope, SpaceLoads,Schedules, and HVAC.
Public Class Methods
get_date_from_string(datestring)
click to toggle source
This method gets a date from a string. @author phylroy.lopez@nrcan.gc.ca @param datestring [String] a date string
# File lib/openstudio-standards/btap/btap.rb, line 323 def self.get_date_from_string(datestring) month = datestring.split("-")[0].to_s day = datestring.split("-")[1].to_i month_list = ["Jan","Feb","Mar","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"] raise ("Month given #{month} is not in format required please enter month with following 3 letter format#{month_list}.") unless month_list.include?(month) OpenStudio::Date.new(OpenStudio::MonthOfYear.new(month),day) end
get_time_from_string(timestring)
click to toggle source
This method gets a time from a string. @author phylroy.lopez@nrcan.gc.ca @param timestring [String] a time string
# File lib/openstudio-standards/btap/btap.rb, line 334 def self.get_time_from_string(timestring) #ensure that it is in 0-24 hour format. hour = timestring.split(":")[0].to_i min = timestring.split(":")[1].to_i raise ("invalid time format #{timestring} please use 0-24 as a range for the hour and 0-59 for range for the minutes: Clock starts at 0:00 and stops at 24:00") if (hour < 0 or hour > 24) or ( min < 0 or min > 59 ) or (hour == 24 and min > 0) OpenStudio::Time.new(timestring) end
validate_array(model,obj_array,object_type)
click to toggle source
This model checks to see if the obj_array passed is the object we require, or if a string is given to search for a object of that strings name. @author Phylroy A. Lopez @param model [OpenStudio::Model::Model] A model object @param obj_array <Object> @param object_type [Object]
# File lib/openstudio-standards/btap/btap.rb, line 277 def self.validate_array(model,obj_array,object_type) command = %Q^#make copy of argument to avoid side effect. object_array = obj_array new_object_array = Array.new() #check if it is not an array unless obj_array.is_a?(Array) if object_array.is_a?(String) #if the arguement is a simple string, convert to an array. object_array = [object_array] #check if it is a single object_type elsif not object_array.to_#{object_type}.empty?() object_array = [object_array] else raise("Object passed is neither a #{object_type} or a name of a #{object_type}. Please choose a #{object_type} name that exists such as :\n\#{object_names.join("\n")}") end end object_array.each do |object| #if it is a string name of an object, try to find it and insert it into the # return array. if object.is_a?(String) if model.get#{object_type}ByName(object).empty? #if we could not find an exact match. raise an exception. object_names = Array.new model.get#{object_type}s.each { |object| object_names << object.name } raise("Object passed is neither a #{object_type} or a name of a #{object_type}. Please choose a #{object_type} name that exists such as :\n\#{object_names.join("\n")}") else new_object_array << model.get#{object_type}ByName(object).get end elsif not object.to_#{object_type}.empty? #if it is already a #{object_type}. insert it into the array. new_object_array << object else raise("invalid object") end end return new_object_array ^ eval(command) end