Class: Tickethub::Aggregate
- Inherits:
-
Object
- Object
- Tickethub::Aggregate
- Defined in:
- lib/tickethub/aggregate.rb
Instance Method Summary collapse
- #average(field) ⇒ Object (also: #avg)
- #count(field = :id) ⇒ Object
-
#initialize(collection, group) ⇒ Aggregate
constructor
A new instance of Aggregate.
- #maximum(field) ⇒ Object (also: #max)
- #minimum(field) ⇒ Object (also: #min)
- #sum(field) ⇒ Object
Constructor Details
#initialize(collection, group) ⇒ Aggregate
Returns a new instance of Aggregate.
4 5 6 7 |
# File 'lib/tickethub/aggregate.rb', line 4 def initialize(collection, group) @group = Array group.dup @collection = collection end |
Instance Method Details
#average(field) ⇒ Object Also known as: avg
21 22 23 |
# File 'lib/tickethub/aggregate.rb', line 21 def average(field) @collection.get aggregate: { field: field, group: @group, operation: 'average' } end |
#count(field = :id) ⇒ Object
31 32 33 |
# File 'lib/tickethub/aggregate.rb', line 31 def count(field = :id) @collection.get aggregate: { field: field, group: @group, operation: 'count' } end |
#maximum(field) ⇒ Object Also known as: max
15 16 17 |
# File 'lib/tickethub/aggregate.rb', line 15 def maximum(field) @collection.get aggregate: { field: field, group: @group, operation: 'maximum' } end |
#minimum(field) ⇒ Object Also known as: min
9 10 11 |
# File 'lib/tickethub/aggregate.rb', line 9 def minimum(field) @collection.get aggregate: { field: field, group: @group, operation: 'minimum' } end |
#sum(field) ⇒ Object
27 28 29 |
# File 'lib/tickethub/aggregate.rb', line 27 def sum(field) @collection.get aggregate: { field: field, group: @group, operation: 'sum' } end |