Class: Differential::Calculator::Totals
- Inherits:
-
Object
- Object
- Differential::Calculator::Totals
- Includes:
- Side
- Defined in:
- lib/differential/calculator/totals.rb
Overview
Value object that can capture basic calculations:
-
a_sigma is the sum of data set A’s values.
-
b_sigma is the sum of data set B’s values.
-
delta is the difference: b_sigma - a_sigma.
Constant Summary
Constants included from Side
Instance Attribute Summary collapse
-
#a_sigma ⇒ Object
readonly
Returns the value of attribute a_sigma.
-
#b_sigma ⇒ Object
readonly
Returns the value of attribute b_sigma.
Instance Method Summary collapse
- #add(value, side) ⇒ Object
- #delta ⇒ Object
-
#initialize ⇒ Totals
constructor
A new instance of Totals.
Constructor Details
#initialize ⇒ Totals
Returns a new instance of Totals.
21 22 23 24 |
# File 'lib/differential/calculator/totals.rb', line 21 def initialize @a_sigma = 0 @b_sigma = 0 end |
Instance Attribute Details
#a_sigma ⇒ Object (readonly)
Returns the value of attribute a_sigma.
19 20 21 |
# File 'lib/differential/calculator/totals.rb', line 19 def a_sigma @a_sigma end |
#b_sigma ⇒ Object (readonly)
Returns the value of attribute b_sigma.
19 20 21 |
# File 'lib/differential/calculator/totals.rb', line 19 def b_sigma @b_sigma end |
Instance Method Details
#add(value, side) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/differential/calculator/totals.rb', line 30 def add(value, side) case side when A @a_sigma += value when B @b_sigma += value else raise ArgumentError, "unknown side: #{side}" end self end |
#delta ⇒ Object
26 27 28 |
# File 'lib/differential/calculator/totals.rb', line 26 def delta b_sigma - a_sigma end |