Module: Workarea::Admin::Insights::InsightsDetails

Extended by:
ActiveSupport::Concern
Includes:
CalculatePercentChange
Included in:
CategoryViewModel, DiscountViewModel, ProductViewModel, SearchViewModel, SegmentViewModel
Defined in:
app/view_models/workarea/admin/insights/insights_details.rb

Instance Method Summary collapse

Instance Method Details

#current_periodObject



69
70
71
72
73
# File 'app/view_models/workarea/admin/insights/insights_details.rb', line 69

def current_period
  @current_period ||= instance_exec(&insights_scoping)
    .by_date_range(starts_at: starts_at, ends_at: ends_at)
    .to_a
end

#ends_atObject



57
58
59
# File 'app/view_models/workarea/admin/insights/insights_details.rb', line 57

def ends_at
  @ends_at ||= Time.zone.parse(options[:ends_at].to_s) || Time.current rescue Time.current
end

#previous_ends_atObject



65
66
67
# File 'app/view_models/workarea/admin/insights/insights_details.rb', line 65

def previous_ends_at
  @previous_ends_at ||= (starts_at - 1.day).end_of_day
end

#previous_periodObject



75
76
77
78
79
# File 'app/view_models/workarea/admin/insights/insights_details.rb', line 75

def previous_period
  @previous_period ||= instance_exec(&insights_scoping)
    .by_date_range(starts_at: previous_starts_at, ends_at: previous_ends_at)
    .to_a
end

#previous_starts_atObject



61
62
63
# File 'app/view_models/workarea/admin/insights/insights_details.rb', line 61

def previous_starts_at
  @previous_starts_at ||= starts_at - (ends_at - starts_at).seconds - 1.day
end

#starts_atObject



52
53
54
55
# File 'app/view_models/workarea/admin/insights/insights_details.rb', line 52

def starts_at
  default = Workarea.config.reports_default_starts_at.call
  @starts_at ||= Time.zone.parse(options[:starts_at].to_s) || default rescue default
end