Class: JsonapiCompliable::Stats::Payload
- Inherits:
-
Object
- Object
- JsonapiCompliable::Stats::Payload
- Defined in:
- lib/jsonapi_compliable/stats/payload.rb
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize(resource, query_hash, scope) ⇒ Payload
constructor
A new instance of Payload.
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
#generate ⇒ Object
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 |