Class: OpenStudio::Model::ModelObject

Inherits:
Object
  • Object
show all
Defined in:
lib/measures/openstudio_results/resources/Siz.ModelObject.rb

Overview

******************************************************************************* OpenStudio®, Copyright © Alliance for Sustainable Energy, LLC. See also openstudio.net/license *******************************************************************************

Instance Method Summary collapse

Instance Method Details

#cast_to_concrete_typeObject?

Convert object to a concrete class if possible of its concrete class, returns the object casted to its concrete class if it was casted successfully.

Returns:

  • (Object, nil)

    returns nil if the object was already



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/measures/openstudio_results/resources/Siz.ModelObject.rb', line 11

def cast_to_concrete_type
  # puts "Casting '#{name}' to concrete type from #{caller_locations(1,1)[0].label}"
  # Get the class type and the IDD object type
  comp_class = self.class.name.to_s.gsub('OpenStudio::Model::', '')
  comp_type = iddObject.type.valueDescription.gsub('OS:', '').delete(':')
  case comp_type
  when 'CoilCoolingLowTemperatureRadiantVariableFlow'
    comp_type = 'CoilCoolingLowTempRadiantVarFlow'
  when 'CoilHeatingLowTemperatureRadiantVariableFlow'
    comp_type = 'CoilHeatingLowTempRadiantVarFlow'
  when 'ZoneHVACLowTemperatureRadiantVariableFlow'
    comp_type = 'ZoneHVACLowTempRadiantVarFlow'
  end
  # If the class type and the IDD object type are identical,
  # this means that the object is already of the concrete class.
  if comp_class == comp_type
    # puts "INFO: #{name} of type #{comp_type} is already concrete"
    return nil
  end
  # Cast the object to its concrete class type
  cast_method = "to_#{comp_type}"
  if respond_to?(cast_method)
    return public_send(cast_method).get
  else
    puts "ERROR: #{name} of type #{comp_type} cannot be made concrete using #{cast_method}"
    # raise "ERROR: #{name} of type #{comp_type} cannot be made concrete using #{cast_method}"
    return nil
  end
end