Class: Tickethub::Aggregate

Inherits:
Object
  • Object
show all
Defined in:
lib/tickethub/aggregate.rb

Instance Method Summary collapse

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