Module: BTAP::Common
- Defined in:
- lib/openstudio-standards/btap/btap.rb
Overview
This contains methods for creation and querying object that deal with Envelope, SpaceLoads,Schedules, and HVAC.
Class Method Summary collapse
-
.get_date_from_string(datestring) ⇒ Object
This method gets a date from a string.
-
.get_time_from_string(timestring) ⇒ Object
This method gets a time from a string.
-
.validate_array(model, obj_array, object_type) ⇒ Object
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.
Class Method Details
.get_date_from_string(datestring) ⇒ Object
This method gets a date from a string.
206 207 208 209 210 211 212 |
# File 'lib/openstudio-standards/btap/btap.rb', line 206 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) ⇒ Object
This method gets a time from a string.
217 218 219 220 221 222 223 |
# File 'lib/openstudio-standards/btap/btap.rb', line 217 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) ⇒ Object
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.
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/openstudio-standards/btap/btap.rb', line 161 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 |