Class: Matey::TopEventsComponent
- Inherits:
-
ApplicationComponent
- Object
- ViewComponent::Base
- ApplicationComponent
- Matey::TopEventsComponent
- Defined in:
- app/components/matey/top_events_component.rb
Instance Method Summary collapse
-
#initialize(events:, time_window: 1.week, limit: 5, color_scheme: "neutral") ⇒ TopEventsComponent
constructor
A new instance of TopEventsComponent.
Methods inherited from ApplicationComponent
Methods included from ColorSchemeHelper
Constructor Details
#initialize(events:, time_window: 1.week, limit: 5, color_scheme: "neutral") ⇒ TopEventsComponent
Returns a new instance of TopEventsComponent.
4 5 6 7 8 9 10 11 12 |
# File 'app/components/matey/top_events_component.rb', line 4 def initialize(events:, time_window: 1.week, limit: 5, color_scheme: "neutral") raise ArgumentError unless events.is_a?(ActiveRecord::Relation) raise ArgumentError unless time_window.is_a?(Integer) @events = events.where(time: time_window.ago..Time.current).limit(limit).order("count(name) DESC").group(:name).count @time_window = time_window @color_scheme = color_scheme(scheme: color_scheme) end |