Class: Streamer::Functors::Average

Inherits:
Functor
  • Object
show all
Defined in:
lib/streamer/functors/average.rb

Overview

Average gives the average of a list given a property.

Instance Attribute Summary

Attributes inherited from Functor

#options, #payload

Instance Method Summary collapse

Methods inherited from Functor

#class_name, #initialize, #type_name

Constructor Details

This class inherits a constructor from Streamer::Functors::Functor

Instance Method Details

#callObject



5
6
7
8
9
10
# File 'lib/streamer/functors/average.rb', line 5

def call
  Divide.new(
    payload,
    terms: [total, count]
  ).call
end

#countObject



20
21
22
# File 'lib/streamer/functors/average.rb', line 20

def count
  Count.new(payload, list: options.fetch(:list)).call
end

#totalObject



12
13
14
15
16
17
18
# File 'lib/streamer/functors/average.rb', line 12

def total
  Sum.new(
    payload,
    list: options.fetch(:list),
    property: options.fetch(:property)
  ).call
end