Class: TokenHawk::DashboardQuery
- Inherits:
-
Object
- Object
- TokenHawk::DashboardQuery
- Defined in:
- lib/token_hawk/dashboard_query.rb
Instance Method Summary collapse
- #daily_costs ⇒ Object
-
#initialize(since:) ⇒ DashboardQuery
constructor
A new instance of DashboardQuery.
- #monthly_total ⇒ Object
- #top_domains ⇒ Object
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 |