Class: RoomType

Inherits:
ApplicationRecord show all
Defined in:
app/models/room_type.rb

Overview

== Schema Information

Table name: room_types
Database name: primary

id :integer not null, primary key
environment :string(50)
friendly_name :string
name :string(32) not null
parent_room :string
seo_key :string
tire_tracks_option :boolean

Indexes

idx_environment (environment)
index_room_types_on_name (name)
index_room_types_on_seo_key (seo_key)

Constant Summary collapse

ROOM_ICON_FILE_BASENAME_BY_RT_ID =
{ '2' => 'bathroom', '4' => 'bedroom', '10' => 'kitchen', '1' => 'basement', '22' => 'basement', '18' => 'other-room', '20' => 'driveway', '21' => 'crosswalk', '29' => 'tiles', '23' => 'patio-chair' }
MINIMUM_SQFT_FOR_IQ =
{ indoor: 2.6, outdoor: 10.0 }

Instance Attribute Summary collapse

Has many collapse

Has and belongs to many collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation

Methods included from Models::EventPublishable

#publish_event

Instance Attribute Details

#nameObject (readonly)



35
# File 'app/models/room_type.rb', line 35

validates :name, presence: true

Class Method Details

.by_environmentActiveRecord::Relation<RoomType>

A relation of RoomTypes that are by environment. Active Record Scope

Returns:

See Also:



33
# File 'app/models/room_type.rb', line 33

scope :by_environment, ->(ev) { where(environment: ev).by_name }

.by_nameActiveRecord::Relation<RoomType>

A relation of RoomTypes that are by name. Active Record Scope

Returns:

See Also:



28
# File 'app/models/room_type.rb', line 28

scope :by_name, -> { order(:name) }

.grouped_by_environment_for_select(is_public = nil) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'app/models/room_type.rb', line 76

def self.grouped_by_environment_for_select(is_public = nil)
  if is_public
    envs = HeatingElementProductLineOption.options_scope(is_public: true).distinct.pluck(:environment)
    rts = RoomType.by_environment(envs).to_a
  else
    rts = RoomType.all
  end
  rt_by_env = rts.group_by(&:environment)
  rt_by_env.each do |k, v|
    rt_by_env[k] = v.map { |r| [r.name, r.id] }
  end
  rt_by_env
end

.indoorActiveRecord::Relation<RoomType>

A relation of RoomTypes that are indoor. Active Record Scope

Returns:

See Also:



31
# File 'app/models/room_type.rb', line 31

scope :indoor, -> { where(environment: 'Indoor').by_name }

.indoorsActiveRecord::Relation<RoomType>

A relation of RoomTypes that are indoors. Active Record Scope

Returns:

See Also:



29
# File 'app/models/room_type.rb', line 29

scope :indoors, -> { where(environment: 'Indoor').by_name }

.options_by_environment_cached(environment) ⇒ Object

Cached room type options for quote builder (by seo_key and name)



66
67
68
69
70
71
72
73
74
# File 'app/models/room_type.rb', line 66

def self.options_by_environment_cached(environment)
  Rails.cache.fetch(['room_type_options', environment], expires_in: 1.hour) do
    select(:name, :seo_key)
      .where(environment:)
      .pluck(:seo_key, :name)
      .sort_by { |rt| rt[1] }
      .map { |rt| { key: rt[0], value: rt[1] } }
  end
end

.options_for_select(ev = nil, parameterize = false) ⇒ Object



55
56
57
58
59
60
61
62
63
# File 'app/models/room_type.rb', line 55

def self.options_for_select(ev = nil, parameterize = false)
  res = all.order(:name)
  res = res.by_environment(ev) if ev.present?
  if parameterize
    res.map { |f| [f.name, f.name.parameterize] }
  else
    res.map { |f| [f.name, f.id] }
  end
end

.outdoorActiveRecord::Relation<RoomType>

A relation of RoomTypes that are outdoor. Active Record Scope

Returns:

See Also:



32
# File 'app/models/room_type.rb', line 32

scope :outdoor, -> { where(environment: 'Outdoor').by_name }

.outdoorsActiveRecord::Relation<RoomType>

A relation of RoomTypes that are outdoors. Active Record Scope

Returns:

See Also:



30
# File 'app/models/room_type.rb', line 30

scope :outdoors, -> { where(environment: 'Outdoor').by_name }

Instance Method Details

#design_tool_fixturesActiveRecord::Relation<DesignToolFixture>

Returns:

See Also:



25
# File 'app/models/room_type.rb', line 25

has_and_belongs_to_many :design_tool_fixtures

#heating_element_product_line_optionsActiveRecord::Relation<HeatingElementProductLineOption>

Returns:

See Also:



22
# File 'app/models/room_type.rb', line 22

has_many :heating_element_product_line_options, inverse_of: :room_type

#is_indoor?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'app/models/room_type.rb', line 47

def is_indoor?
  environment == 'Indoor'
end

#is_outdoor?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'app/models/room_type.rb', line 51

def is_outdoor?
  environment == 'Outdoor'
end

#minimum_sqft_for_iqObject



41
42
43
44
45
# File 'app/models/room_type.rb', line 41

def minimum_sqft_for_iq
  env_sym = :indoor
  env_sym = environment.to_s.downcase.to_sym if environment.present?
  MINIMUM_SQFT_FOR_IQ[(env_sym)]
end

#roomsActiveRecord::Relation<Room>

Returns:

  • (ActiveRecord::Relation<Room>)

See Also:



21
# File 'app/models/room_type.rb', line 21

has_many :rooms

#showcasesActiveRecord::Relation<Showcase>

Returns:

See Also:



23
# File 'app/models/room_type.rb', line 23

has_many :showcases

#storesActiveRecord::Relation<Store>

Returns:

  • (ActiveRecord::Relation<Store>)

See Also:



26
# File 'app/models/room_type.rb', line 26

has_and_belongs_to_many :stores