module Chartable::ActiveRecordExtension
Public Instance Methods
analytics(period, from: nil, to: nil, on: 'created_at', order: 'asc')
click to toggle source
It returns analytics hash created from the given criteria
@return [Hash]
# File lib/chartable/active_record_extension.rb, line 12 def analytics(period, from: nil, to: nil, on: 'created_at', order: 'asc') query_order = if order.to_s.downcase == 'desc' 'desc' else 'asc' end period_query = Chartable::PeriodQuery.build(period) scope = Chartable::RangeQuery.call(self, on: on, from: from, to: to) period_query.call(scope, on: on, order: query_order) end