Class: TokenHawk::DashboardQuery

Inherits:
Object
  • Object
show all
Defined in:
lib/token_hawk/dashboard_query.rb

Instance Method Summary collapse

Constructor Details

#initialize(since:) ⇒ DashboardQuery

Returns a new instance of DashboardQuery.



5
6
7
# File 'lib/token_hawk/dashboard_query.rb', line 5

def initialize(since:)
  @since = since
end

Instance Method Details

#daily_costs ⇒ Object



20
21
22
23
24
# File 'lib/token_hawk/dashboard_query.rb', line 20

def daily_costs
  scope.group(Arel.sql("DATE(created_at)"))
       .sum(:total_cost_cents)
       .sort_by { |date, _| date }
end

#monthly_total ⇒ Object



9
10
11
# File 'lib/token_hawk/dashboard_query.rb', line 9

def monthly_total
  scope.sum(:total_cost_cents)
end

#top_domains ⇒ Object



13
14
15
16
17
18
# File 'lib/token_hawk/dashboard_query.rb', line 13

def top_domains
  scope.group(:domain)
       .sum(:total_cost_cents)
       .sort_by { |_, cost| -cost }
       .first(3)
end