Class: Matey::TopEventsComponent

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

Instance Method Summary collapse

Methods inherited from ApplicationComponent

#before_render

Methods included from ColorSchemeHelper

#color_scheme

Constructor Details

#initialize(events:, time_window: 1.week, limit: 5, color_scheme: "neutral") ⇒ TopEventsComponent

Returns a new instance of TopEventsComponent.

Raises:

  • (ArgumentError)


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