Class: Streamer::Functors::Divide

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

Overview

Divide divides two 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/divide.rb', line 5

def call
  divide
end

#divideObject



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

def divide
  terms = numerify(options.fetch(:terms))
  fail 'Streamer::Functor# divide: too many terms' if terms.size > 2
  return 0.0 if terms.any? { |t| t.to_f == 0.0 }
  terms[0].to_f / terms[1].to_f
end