lib/differential/calculator/totals.rb in differential-1.0.2 vs lib/differential/calculator/totals.rb in differential-1.0.3
- old
+ new
@@ -14,31 +14,56 @@
# - b_sigma is the sum of data set B's values.
# - delta is the difference: b_sigma - a_sigma.
class Totals
include ::Differential::Calculator::Side
- attr_reader :a_sigma, :b_sigma
+ attr_reader :a_sigma,
+ :a_size,
+ :b_sigma,
+ :b_size
def initialize
@a_sigma = 0
+ @a_size = 0
@b_sigma = 0
+ @b_size = 0
end
def delta
b_sigma - a_sigma
end
def add(value, side)
+ increment_sigma(value, side)
+ increment_size(side)
+ end
+
+ private
+
+ def increment_sigma(value, side)
case side
when A
@a_sigma += value
when B
@b_sigma += value
else
raise ArgumentError, "unknown side: #{side}"
end
- self
+ nil
+ end
+
+ def increment_size(side)
+ case side
+ when A
+ @a_size += 1.0
+ when B
+ @b_size += 1.0
+ else
+ raise ArgumentError, "unknown side: #{side}"
+ end
+
+ nil
end
end
end
end