Class: JsonapiCompliable::Stats::Payload

Inherits:
Object
  • Object
show all
Defined in:
lib/jsonapi_compliable/stats/payload.rb

Instance Method Summary collapse

Constructor Details

#initialize(resource, query_hash, scope) ⇒ Payload

Returns a new instance of Payload.



4
5
6
7
8
# File 'lib/jsonapi_compliable/stats/payload.rb', line 4

def initialize(resource, query_hash, scope)
  @resource   = resource
  @query_hash = query_hash[:stats]
  @scope      = scope
end

Instance Method Details

#generateObject



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/jsonapi_compliable/stats/payload.rb', line 10

def generate
  {}.tap do |stats|
    @query_hash.each_pair do |name, calculation|
      stats[name] = {}

      each_calculation(name, calculation) do |calc, function|
        stats[name][calc] = function.call(@scope, name)
      end
    end
  end
end