Class: BestBoy::MonthReport

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
ObeysTestMode, Reporting
Defined in:
app/models/best_boy/month_report.rb

Class Method Summary collapse

Methods included from ObeysTestMode

#save, #save!

Class Method Details

.create_for(owner, type, source = nil, date = Time.zone.now) ⇒ Object



40
41
42
43
44
45
46
47
48
# File 'app/models/best_boy/month_report.rb', line 40

def create_for(owner, type, source = nil, date = Time.zone.now)
  month_report              = BestBoy::MonthReport.new
  month_report.owner_type   = owner.to_s
  month_report.event        = type
  month_report.event_source = source
  month_report.created_at   = date || Time.zone.now

  month_report.save ? month_report : nil
end

.monthly_occurrences_for(owner, type, source = nil, date) ⇒ Object



50
51
52
# File 'app/models/best_boy/month_report.rb', line 50

def monthly_occurrences_for(owner, type, source = nil, date)
  MonthReport.for(owner, type, source).between(date.beginning_of_month, date.end_of_month).sum(:occurrences)
end

.overall_occurrences_for(owner, type, source = nil) ⇒ Object



58
59
60
# File 'app/models/best_boy/month_report.rb', line 58

def overall_occurrences_for(owner, type, source = nil)
  MonthReport.for(owner, type, source).sum(:occurrences)
end

.yearly_occurrences_for(owner, type, source = nil, date) ⇒ Object



54
55
56
# File 'app/models/best_boy/month_report.rb', line 54

def yearly_occurrences_for(owner, type, source = nil, date)
  MonthReport.for(owner, type, source).between(date.beginning_of_year, date).sum(:occurrences)
end