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

Class Method Details

.get_date_from_string(datestring) ⇒ Object

This method gets a date from a string.

Parameters:

  • datestring (String)

    a date string

Author:



340
341
342
343
344
345
346
# File 'lib/openstudio-standards/btap/btap.rb', line 340

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.

Parameters:

  • timestring (String)

    a time string

Author:



351
352
353
354
355
356
357
# File 'lib/openstudio-standards/btap/btap.rb', line 351

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.

Parameters:

  • model (OpenStudio::model::Model)

    A model object

  • obj_array (Object)
  • object_type (Object)

Author:

  • Phylroy A. Lopez



294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
# File 'lib/openstudio-standards/btap/btap.rb', line 294

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