Class: Matey::ActiveUsersComponent
- Inherits:
-
ApplicationComponent
- Object
- ViewComponent::Base
- ApplicationComponent
- Matey::ActiveUsersComponent
- Defined in:
- app/components/matey/active_users_component.rb
Instance Method Summary collapse
-
#initialize(events:, time_window: 1.week, color_scheme: "neutral") ⇒ ActiveUsersComponent
constructor
A new instance of ActiveUsersComponent.
Methods inherited from ApplicationComponent
Methods included from ColorSchemeHelper
Constructor Details
#initialize(events:, time_window: 1.week, color_scheme: "neutral") ⇒ ActiveUsersComponent
Returns a new instance of ActiveUsersComponent.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'app/components/matey/active_users_component.rb', line 4 def initialize(events:, time_window: 1.week, color_scheme: "neutral") raise ArgumentError unless events.is_a?(ActiveRecord::Relation) raise ArgumentError unless time_window.is_a?(Integer) @current_period = events.where(time: time_window.ago..Time.current).pluck(:user_id).uniq.count previous_period = events.where(time: (2 * time_window).ago..time_window.ago).pluck(:user_id).uniq.count @change_active_number = @current_period - previous_period @change_active_percent = ((@change_active_number.to_f / ((previous_period == 0) ? 1 : previous_period)) * 100).truncate(2) @time_window = time_window @color_scheme = color_scheme(scheme: color_scheme) end |