Class: Matey::UserEngagementComponent

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

Instance Method Summary collapse

Methods inherited from ApplicationComponent

#before_render

Methods included from ColorSchemeHelper

#color_scheme

Constructor Details

#initialize(events:, user_id:, time_window: 1.week, limit: 10, color_scheme: "neutral") ⇒ UserEngagementComponent

Returns a new instance of UserEngagementComponent.



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

def initialize(events:, user_id:, time_window: 1.week, limit: 10, color_scheme: "neutral")
  @events_for_user = events.where_props(user_id: user_id).where(time: time_window.ago..Time.current).group(:name).count
  @count_by_event = @events_for_user.sort_by { |event, count| count }.last(limit).reverse
  @time_window = time_window
  @user_id = user_id

  @color_scheme = color_scheme(scheme: color_scheme)
end