Class: Honeybee::ModelObject
- Inherits:
-
Object
- Object
- Honeybee::ModelObject
- Defined in:
- lib/honeybee/model_object.rb,
lib/to_openstudio/model_object.rb,
lib/from_openstudio/model_object.rb
Direct Known Subclasses
AirBoundaryConstructionAbridged, Aperture, ConstructionSetAbridged, DaylightingControl, DesignDay, Door, ElectricEquipmentAbridged, ElectricLoadCenter, EnergyMaterial, EnergyMaterialNoMass, EnergyMaterialVegetation, EnergyWindowFrame, EnergyWindowMaterialBlind, EnergyWindowMaterialGas, EnergyWindowMaterialGasCustom, EnergyWindowMaterialGasMixture, EnergyWindowMaterialGlazing, EnergyWindowMaterialShade, EnergyWindowMaterialSimpleGlazSys, Face, GasEquipmentAbridged, IdealAirSystemAbridged, InfiltrationAbridged, InternalMassAbridged, LightingAbridged, OpaqueConstructionAbridged, PVProperties, PeopleAbridged, ProcessAbridged, ProgramTypeAbridged, Room, ScheduleFixedIntervalAbridged, ScheduleRulesetAbridged, ScheduleTypeLimit, ServiceHotWaterAbridged, SetpointHumidistat, SetpointThermostat, Shade, ShadeConstruction, ShadeMesh, SimulationOutput, TemplateHVAC, VentilationAbridged, VentilationControlAbridged, VentilationFanAbridged, VentilationOpening, VentilationSimulationControl, WindowConstructionAbridged, WindowConstructionDynamicAbridged, WindowConstructionShadeAbridged
Constant Summary collapse
- @@encoding_options =
{ :invalid => :replace, # Replace invalid byte sequences :undef => :replace, # Replace anything not defined in ASCII :replace => '', # Use a blank for those replacements :universal_newline => true # Always break lines with \n }
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Base class from which all other objects in this module inherit.
-
#openstudio_object ⇒ Object
readonly
Returns the value of attribute openstudio_object.
-
#warnings ⇒ Object
readonly
Base class from which all other objects in this module inherit.
Class Method Summary collapse
-
.clean_identifier(str) ⇒ Object
remove illegal characters in identifier.
-
.clean_name(str) ⇒ Object
remove illegal characters in identifier.
-
.read_from_disk(file) ⇒ Object
Read ModelObject JSON from disk.
- .truncate(string, max) ⇒ Object
Instance Method Summary collapse
- #allowable_types ⇒ Object
-
#defaults ⇒ Object
hash containing the object defaults taken from the open API schema.
-
#find_existing_openstudio_object(openstudio_model) ⇒ Object
find an equivalent existing object in the openstudio model, return nil if not found.
-
#initialize(hash) ⇒ ModelObject
constructor
Load ModelObject from symbolized hash.
- #method_missing(sym, *args) ⇒ Object
-
#to_openstudio(openstudio_model) ⇒ Object
create a new object in the openstudio model and return it.
Constructor Details
#initialize(hash) ⇒ ModelObject
Load ModelObject from symbolized hash
89 90 91 92 93 94 95 96 97 98 |
# File 'lib/honeybee/model_object.rb', line 89 def initialize(hash) # initialize class variable @@extension only once @@extension ||= Extension.new @@schema ||= @@extension.schema @hash = hash @type = @hash[:type] raise 'Unknown type' if @type.nil? raise "Incorrect model object type '#{@type}' for '#{self.class.name}'" unless allowable_types.include?(@type) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/honeybee/model_object.rb', line 61 def method_missing(sym, *args) name = sym.to_s aname = name.sub('=', '') asym = aname.to_sym is_getter = args.empty? && @hash.key?(asym) is_setter = (name != aname) && (args.size == 1) && @hash.key?(asym) if is_getter return @hash[asym] elsif is_setter return @hash[asym] = args[0] end # do the regular thing super end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Base class from which all other objects in this module inherit. Attributes and methods of this class should be overwritten in each inheriting object.
51 52 53 |
# File 'lib/honeybee/model_object.rb', line 51 def errors @errors end |
#openstudio_object ⇒ Object (readonly)
Returns the value of attribute openstudio_object.
39 40 41 |
# File 'lib/to_openstudio/model_object.rb', line 39 def openstudio_object @openstudio_object end |
#warnings ⇒ Object (readonly)
Base class from which all other objects in this module inherit. Attributes and methods of this class should be overwritten in each inheriting object.
51 52 53 |
# File 'lib/honeybee/model_object.rb', line 51 def warnings @warnings end |
Class Method Details
.clean_identifier(str) ⇒ Object
remove illegal characters in identifier
121 122 123 124 125 |
# File 'lib/honeybee/model_object.rb', line 121 def self.clean_identifier(str) encode_str = str.encode(Encoding.find('ASCII'), **@@encoding_options) encode_str = truncate(encode_str, 97) encode_str.gsub(/[^.A-Za-z0-9_-]/, '_').gsub(' ', '_') end |
.clean_name(str) ⇒ Object
remove illegal characters in identifier
114 115 116 117 118 |
# File 'lib/honeybee/model_object.rb', line 114 def self.clean_name(str) encode_str = str.encode(Encoding.find('ASCII'), **@@encoding_options) encode_str = truncate(encode_str, 97) encode_str.gsub(/[,;!]/, '_') end |
.read_from_disk(file) ⇒ Object
Read ModelObject JSON from disk
79 80 81 82 83 84 85 86 |
# File 'lib/honeybee/model_object.rb', line 79 def self.read_from_disk(file) hash = nil File.open(File.join(file), 'r') do |f| hash = JSON.parse(File.read(f, :external_encoding => 'UTF-8', :internal_encoding => 'UTF-8'), symbolize_names: true, encoding: 'UTF-8') end new(hash) end |
.truncate(string, max) ⇒ Object
109 110 111 |
# File 'lib/honeybee/model_object.rb', line 109 def self.truncate(string, max) string.length > max ? "#{string[0...max]}..." : string end |
Instance Method Details
#allowable_types ⇒ Object
100 101 102 |
# File 'lib/honeybee/model_object.rb', line 100 def allowable_types [self.class.name.split('::').last] end |
#defaults ⇒ Object
hash containing the object defaults taken from the open API schema
105 106 107 |
# File 'lib/honeybee/model_object.rb', line 105 def defaults raise 'defaults not implemented for ModelObject, override in your class' end |
#find_existing_openstudio_object(openstudio_model) ⇒ Object
find an equivalent existing object in the openstudio model, return nil if not found
42 43 44 |
# File 'lib/to_openstudio/model_object.rb', line 42 def find_existing_openstudio_object(openstudio_model) raise 'find_existing_openstudio_object is not yet implemented for this ModelObject.' end |
#to_openstudio(openstudio_model) ⇒ Object
create a new object in the openstudio model and return it
47 48 49 |
# File 'lib/to_openstudio/model_object.rb', line 47 def to_openstudio(openstudio_model) raise 'to_openstudio is not yet implemented for this ModelObject.' end |