Class: Report::ProjectMetric

Inherits:
Object
  • Object
show all
Defined in:
app/models/report/project_metric.rb

Overview

Helper class scoped to Report.

Constant Summary collapse

VALID_ENVIRONMENTS =

Valid environments.

%w[Countertop Roof Outdoor Indoor Pipe].freeze
VALID_ROOM_TYPES =

Recognised valid room types.

%w[addition basement bathroom bedroom breakfast-nook bridge carport
countertop courtyard custom-mirror dining-room driveway enclosed-porch
ensuite entry entry-hallway exit family-room four-season-room garage
heated-balcony heated-bench home-theater-room kitchen landing laundry
living-room master-bathroom master-bedroom mudroom office other patio
pipe porch powder-room ramp recreation-media-room roof shop-floor
shower-sauna stair sunroom three-season-room valet walkway].freeze

Class Method Summary collapse

Class Method Details

.count_by_project_type(project_type) ⇒ Object



29
30
31
32
33
34
35
# File 'app/models/report/project_metric.rb', line 29

def self.count_by_project_type(project_type)
  raise "Invalid project_type, must be one of #{VALID_ENVIRONMENTS.join(', ')}" unless project_type.in?(VALID_ENVIRONMENTS)

  Rails.cache.fetch([:project_metrics, :count_by_project_type, project_type], expires_in: 7.days) do
    Order.invoiced.joins(room_configurations: :room_type).where(RoomType[:environment].in(project_type)).count
  end
end

.count_by_room_type_seo_key(room_type) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/models/report/project_metric.rb', line 16

def self.count_by_room_type_seo_key(room_type)
  raise "Invalid room_type, must be one of #{VALID_ROOM_TYPES.join(', ')}" unless room_type.in?(VALID_ROOM_TYPES)

  Rails.cache.fetch([:project_metrics, :count_by_room_type_seo_key, room_type], expires_in: 7.days) do
    if room_type.include?('bedroom')
      room_type = %w[master-bedroom bedroom]
    elsif room_type.include?('bathroom')
      room_type = %w[master-bathroom bathroom]
    end
    Order.invoiced.joins(room_configurations: :room_type).where(RoomType[:seo_key].in(room_type)).count
  end
end