Class: Differential::Calculator::Totals

Inherits:
Object
  • Object
show all
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

Side::A, Side::B

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTotals

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_sigmaObject (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_sigmaObject (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

#deltaObject



26
27
28
# File 'lib/differential/calculator/totals.rb', line 26

def delta
  b_sigma - a_sigma
end