Class: Matey::NewActivityComponent
- Inherits:
-
ApplicationComponent
- Object
- ViewComponent::Base
- ApplicationComponent
- Matey::NewActivityComponent
- Defined in:
- app/components/matey/new_activity_component.rb
Instance Method Summary collapse
-
#initialize(events:, time_window: 1.week, color_scheme: "neutral") ⇒ NewActivityComponent
constructor
A new instance of NewActivityComponent.
Methods inherited from ApplicationComponent
Methods included from ColorSchemeHelper
Constructor Details
#initialize(events:, time_window: 1.week, color_scheme: "neutral") ⇒ NewActivityComponent
Returns a new instance of NewActivityComponent.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'app/components/matey/new_activity_component.rb', line 2 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).count previous_period = events.where(time: (2 * time_window).ago..time_window.ago).pluck(:user_id).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 |