Class: RoomType
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- RoomType
- 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
- #name ⇒ Object readonly
Has many collapse
- #heating_element_product_line_options ⇒ ActiveRecord::Relation<HeatingElementProductLineOption>
- #rooms ⇒ ActiveRecord::Relation<Room>
- #showcases ⇒ ActiveRecord::Relation<Showcase>
Has and belongs to many collapse
- #design_tool_fixtures ⇒ ActiveRecord::Relation<DesignToolFixture>
- #stores ⇒ ActiveRecord::Relation<Store>
Class Method Summary collapse
-
.by_environment ⇒ ActiveRecord::Relation<RoomType>
A relation of RoomTypes that are by environment.
-
.by_name ⇒ ActiveRecord::Relation<RoomType>
A relation of RoomTypes that are by name.
- .grouped_by_environment_for_select(is_public = nil) ⇒ Object
-
.indoor ⇒ ActiveRecord::Relation<RoomType>
A relation of RoomTypes that are indoor.
-
.indoors ⇒ ActiveRecord::Relation<RoomType>
A relation of RoomTypes that are indoors.
-
.options_by_environment_cached(environment) ⇒ Object
Cached room type options for quote builder (by seo_key and name).
- .options_for_select(ev = nil, parameterize = false) ⇒ Object
-
.outdoor ⇒ ActiveRecord::Relation<RoomType>
A relation of RoomTypes that are outdoor.
-
.outdoors ⇒ ActiveRecord::Relation<RoomType>
A relation of RoomTypes that are outdoors.
Instance Method Summary collapse
Methods inherited from ApplicationRecord
ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation
Methods included from Models::EventPublishable
Instance Attribute Details
#name ⇒ Object (readonly)
35 |
# File 'app/models/room_type.rb', line 35 validates :name, presence: true |
Class Method Details
.by_environment ⇒ ActiveRecord::Relation<RoomType>
A relation of RoomTypes that are by environment. Active Record Scope
33 |
# File 'app/models/room_type.rb', line 33 scope :by_environment, ->(ev) { where(environment: ev).by_name } |
.by_name ⇒ ActiveRecord::Relation<RoomType>
A relation of RoomTypes that are by name. Active Record Scope
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.(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 |
.indoor ⇒ ActiveRecord::Relation<RoomType>
A relation of RoomTypes that are indoor. Active Record Scope
31 |
# File 'app/models/room_type.rb', line 31 scope :indoor, -> { where(environment: 'Indoor').by_name } |
.indoors ⇒ ActiveRecord::Relation<RoomType>
A relation of RoomTypes that are indoors. Active Record Scope
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.(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.(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 |
.outdoor ⇒ ActiveRecord::Relation<RoomType>
A relation of RoomTypes that are outdoor. Active Record Scope
32 |
# File 'app/models/room_type.rb', line 32 scope :outdoor, -> { where(environment: 'Outdoor').by_name } |
.outdoors ⇒ ActiveRecord::Relation<RoomType>
A relation of RoomTypes that are outdoors. Active Record Scope
30 |
# File 'app/models/room_type.rb', line 30 scope :outdoors, -> { where(environment: 'Outdoor').by_name } |
Instance Method Details
#design_tool_fixtures ⇒ ActiveRecord::Relation<DesignToolFixture>
25 |
# File 'app/models/room_type.rb', line 25 has_and_belongs_to_many :design_tool_fixtures |
#heating_element_product_line_options ⇒ ActiveRecord::Relation<HeatingElementProductLineOption>
22 |
# File 'app/models/room_type.rb', line 22 has_many :heating_element_product_line_options, inverse_of: :room_type |
#is_indoor? ⇒ Boolean
47 48 49 |
# File 'app/models/room_type.rb', line 47 def is_indoor? environment == 'Indoor' end |
#is_outdoor? ⇒ Boolean
51 52 53 |
# File 'app/models/room_type.rb', line 51 def is_outdoor? environment == 'Outdoor' end |
#minimum_sqft_for_iq ⇒ Object
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 |
#rooms ⇒ ActiveRecord::Relation<Room>
21 |
# File 'app/models/room_type.rb', line 21 has_many :rooms |
#showcases ⇒ ActiveRecord::Relation<Showcase>
23 |
# File 'app/models/room_type.rb', line 23 has_many :showcases |
#stores ⇒ ActiveRecord::Relation<Store>
26 |
# File 'app/models/room_type.rb', line 26 has_and_belongs_to_many :stores |