Class: Streamer::Functors::Subtract

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

Overview

Subtract subtracts a set of terms

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
# File 'lib/streamer/functors/subtract.rb', line 5

def call
  subtract
end

#subtractObject



9
10
11
12
13
14
15
# File 'lib/streamer/functors/subtract.rb', line 9

def subtract
  terms = options.fetch(:terms)
  initial_prop = terms.shift
  terms.inject(prop(initial_prop).to_f) do |total, item|
    total - prop(item).to_f
  end
end