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

Constants included from Schedulable

Schedulable::SIMPLE_FORM_OPTIONS

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 Schedulable

config

Methods included from Models::AfterCommittable

#after_commit

Methods included from Models::EventPublishable

#publish_event

Instance Attribute Details

#areaObject (readonly)



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

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

Instance Method Details

#ceilingCeiling

Returns:

See Also:

Validations:



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

belongs_to :ceiling, optional: true

#check_insulation_or_u_valueObject (protected)



77
78
79
80
81
82
83
84
# File 'app/models/skylight.rb', line 77

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'}"
  return unless user_u_value.blank? && (skylight_glass_type.nil? || skylight_frame_type.nil? || skylight_insulation_type.nil?)

  errors.add(:skylight_glass_type_id, "required AND") if skylight_glass_type.nil?
  errors.add(:skylight_frame_type_id, "required OR")
  errors.add(:user_u_value, "required")
end

#check_sibling_areas_less_than_parentObject (protected)



73
74
75
# File 'app/models/skylight.rb', line 73

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

#heat_loss_nameObject



61
62
63
# File 'app/models/skylight.rb', line 61

def heat_loss_name
  name
end

#nameObject



53
54
55
56
57
58
59
# File 'app/models/skylight.rb', line 53

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

#room_configurationObject

Alias for Ceiling#room_configuration

Returns:

  • (Object)

    Ceiling#room_configuration

See Also:



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

delegate :room_configuration, to: :ceiling

#set_skylight_insulation_typeObject (protected)



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

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: skylight_glass_type_id).where(skylight_frame_type_id: skylight_frame_type_id).first if skylight_glass_type_id.present? && skylight_frame_type_id.present?
  # puts "set_skylight_insulation_type: self.skylight_insulation_type_id: #{self.skylight_insulation_type_id}"
end

#skylight_frame_typeSkylightFrameType



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

belongs_to :skylight_frame_type, optional: true

#skylight_glass_typeSkylightGlassType



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

belongs_to :skylight_glass_type, optional: true

#skylight_insulation_typeSkylightInsulationType



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

belongs_to :skylight_insulation_type, optional: true