Class: Matey::UserEngagementComponent
- Inherits:
-
ApplicationComponent
- Object
- ViewComponent::Base
- ApplicationComponent
- Matey::UserEngagementComponent
- Defined in:
- app/components/matey/user_engagement_component.rb
Instance Method Summary collapse
-
#initialize(events:, user_id:, time_window: 1.week, limit: 10, color_scheme: "neutral") ⇒ UserEngagementComponent
constructor
A new instance of UserEngagementComponent.
Methods inherited from ApplicationComponent
Methods included from ColorSchemeHelper
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 |