Class: Skylight

Inherits:
ApplicationRecord show all
Includes:
Models::Auditable, Models::HeatLossable
Defined in:
app/models/skylight.rb

Overview

== Schema Information

Table name: skylights
Database name: primary

id :integer not null, primary key
area :float
user_u_value :float
ceiling_id :integer
skylight_frame_type_id :integer
skylight_glass_type_id :integer
skylight_insulation_type_id :integer

Indexes

skylights_ceiling_id_idx (ceiling_id)
skylights_skylight_frame_type_id_idx (skylight_frame_type_id)
skylights_skylight_glass_type_id_idx (skylight_glass_type_id)
skylights_skylight_insulation_type_id_idx (skylight_insulation_type_id)

Foreign Keys

skylights_ceiling_id_fk (ceiling_id => ceilings.id) ON DELETE => cascade
skylights_skylight_frame_type_id_fk (skylight_frame_type_id => skylight_frame_types.id)
skylights_skylight_glass_type_id_fk (skylight_glass_type_id => skylight_glass_types.id)
skylights_skylight_insulation_type_id_fk (skylight_insulation_type_id => skylight_insulation_types.id)

Constant Summary

Constants included from HeatLossableConstants

HeatLossableConstants::BTU_PER_HOUR_PER_WATT, HeatLossableConstants::HIGH_U_VALUE_THRESHOLD, HeatLossableConstants::HLC_PRIMARY_OK_THRESHOLD, HeatLossableConstants::INFILTRATION_AREA_FACTORS, HeatLossableConstants::INFILTRATION_FIREPLACE_FACTORS, HeatLossableConstants::INFILTRATION_SEALING_FACTORS, HeatLossableConstants::PIE_CHART_FLAG_COLORS, HeatLossableConstants::PIE_CHART_OK_COLORS

Constants included from Models::Auditable

Models::Auditable::ALWAYS_IGNORED

Instance Attribute Summary collapse

Belongs to collapse

Methods included from Models::Auditable

#creator, #updater

Delegated Instance Attributes collapse

Instance Method Summary collapse

Methods included from Models::HeatLossable

#children_heat_loss_recursive, #get_children_heat_loss, #get_heat_loss, #get_self_and_children_heat_loss, #get_u_value, #heat_loss_children, #heat_loss_children_recursive, #insulation_type, #reset_room_last_heat_loss, #self_and_children_heat_loss_recursive

Methods included from Models::Auditable

#all_skipped_columns, #audit_reference_data, #should_not_save_version, #stamp_record

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation

Methods included from Models::EventPublishable

#publish_event

Instance Attribute Details

#areaObject (readonly)



46
# File 'app/models/skylight.rb', line 46

validates :area, :numericality => { :less_than_or_equal_to => 9999.9, :greater_than => 0.0 }

Instance Method Details

#ceilingCeiling

Returns:

See Also:



39
# File 'app/models/skylight.rb', line 39

belongs_to :ceiling, optional: true

#check_insulation_or_u_valueObject (protected)



74
75
76
77
78
79
80
81
# File 'app/models/skylight.rb', line 74

def check_insulation_or_u_value
  # puts "check_insulation_or_u_value: self.user_u_value: #{self.user_u_value} self.skylight_glass_type.name: #{self.skylight_glass_type.name rescue 'not defined'} self.skylight_frame_type.name: #{self.skylight_frame_type.name rescue 'not defined'} self.skylight_insulation_type.name: #{self.skylight_insulation_type.name rescue 'not defined'}"
  if self.user_u_value.blank? and (self.skylight_glass_type.nil? or self.skylight_frame_type.nil? or self.skylight_insulation_type.nil?)
    errors.add(:skylight_glass_type_id, "required AND") if self.skylight_glass_type.nil?
    errors.add(:skylight_frame_type_id, "required OR")
    errors.add(:user_u_value, "required")
  end
end

#check_sibling_areas_less_than_parentObject (protected)



68
69
70
71
72
# File 'app/models/skylight.rb', line 68

def check_sibling_areas_less_than_parent
  if self.area and (self.area + self.ceiling.skylights.reject{|s| s.id == (self.id || -1)}.sum{|w| w.area}) >= self.ceiling.area
    errors.add(:area, "plus areas of other skylights can't exceed ceiling area")
  end
end

#heat_loss_nameObject



56
57
58
# File 'app/models/skylight.rb', line 56

def heat_loss_name
  self.name
end

#nameObject



52
53
54
# File 'app/models/skylight.rb', line 52

def name
  "Skylight: #{(self.ceiling.skylight_ids.index(self.id) + 1) rescue 'New'}"
end

#room_configurationObject

Alias for Ceiling#room_configuration

Returns:

  • (Object)

    Ceiling#room_configuration

See Also:



50
# File 'app/models/skylight.rb', line 50

delegate :room_configuration, :to => :ceiling

#set_skylight_insulation_typeObject (protected)



62
63
64
65
66
# File 'app/models/skylight.rb', line 62

def set_skylight_insulation_type
  # puts "set_skylight_insulation_type: self.skylight_glass_type_id: #{self.skylight_glass_type_id} self.skylight_frame_type_id: #{self.skylight_frame_type_id}"
  self.skylight_insulation_type = SkylightInsulationType.where(:skylight_glass_type_id => self.skylight_glass_type_id).where(:skylight_frame_type_id => self.skylight_frame_type_id).first if (self.skylight_glass_type_id.present? and self.skylight_frame_type_id.present?)
  # puts "set_skylight_insulation_type: self.skylight_insulation_type_id: #{self.skylight_insulation_type_id}"
end

#skylight_frame_typeSkylightFrameType



41
# File 'app/models/skylight.rb', line 41

belongs_to :skylight_frame_type, optional: true

#skylight_glass_typeSkylightGlassType



40
# File 'app/models/skylight.rb', line 40

belongs_to :skylight_glass_type, optional: true

#skylight_insulation_typeSkylightInsulationType



42
# File 'app/models/skylight.rb', line 42

belongs_to :skylight_insulation_type, optional: true