Class: Matey::VisitsByDayOfWeekComponent

Inherits:
ApplicationComponent show all
Defined in:
app/components/matey/visits_by_day_of_week_component.rb

Instance Method Summary collapse

Methods inherited from ApplicationComponent

#before_render

Methods included from ColorSchemeHelper

#color_scheme

Constructor Details

#initialize(visits:, time_window: 1.month, exclude_days: [], color_scheme: "neutral") ⇒ VisitsByDayOfWeekComponent

Returns a new instance of VisitsByDayOfWeekComponent.



5
6
7
8
9
10
# File 'app/components/matey/visits_by_day_of_week_component.rb', line 5

def initialize(visits:, time_window: 1.month, exclude_days: [], color_scheme: "neutral")
  @visits = visits
  @time_window = time_window
  @exclude_days = exclude_days
  @color_scheme = color_scheme(scheme: color_scheme)
end

Instance Method Details

#visits_by_day_of_weekObject

group visits by day in provided time window



13
14
15
16
# File 'app/components/matey/visits_by_day_of_week_component.rb', line 13

def visits_by_day_of_week
  visits_by_day_of_week = @visits.group_by_day_of_week(:started_at, format: "%A", range: @time_window.ago..).count
  visits_by_day_of_week.except!(*@exclude_days) if @exclude_days.any?
end