Class: Opower::TimeSeries::SyntheticResult::TimeSeriesCalculator
- Inherits:
-
Dentaku::Calculator
- Object
- Dentaku::Calculator
- Opower::TimeSeries::SyntheticResult::TimeSeriesCalculator
- Defined in:
- lib/time_series/results/synthetic_result.rb
Overview
Subclass of Dentaku’s calculator - adds math functions by default
Instance Method Summary collapse
-
#initialize ⇒ TimeSeriesCalculator
constructor
A new instance of TimeSeriesCalculator.
-
#initialize_math_functions ⇒ Object
Initializes math functions provided by Ruby and places them into the calculator as functions.
Constructor Details
#initialize ⇒ TimeSeriesCalculator
Returns a new instance of TimeSeriesCalculator.
45 46 47 48 |
# File 'lib/time_series/results/synthetic_result.rb', line 45 def initialize super initialize_math_functions end |
Instance Method Details
#initialize_math_functions ⇒ Object
Initializes math functions provided by Ruby and places them into the calculator as functions. NOTE: You must wrap nested mathematical expressions in formulas or Dentaku will attempt to pass them as separate arguments into the lambda below! This method smells of :reek:NestedIterators
For example: Assume x = 1, y = 2 cos(x + y) is translated into cos(1, ‘add’, 2) - this calls Math.cos(1, ‘add’, 2) cos((x + y)) is translated into cos(3) - this correctly calls Math.cos(3)
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/time_series/results/synthetic_result.rb', line 59 def initialize_math_functions Math.methods(false).each do |method| math_method = Math.method(method) add_function( name: method, type: :numeric, signature: [:numeric], body: ->(*args) { math_method.call(*args) } ) end end |