From 5d14d039631c9bceed02af0ea44af197832ed5bb Mon Sep 17 00:00:00 2001 From: Jose Farias Date: Thu, 18 Apr 2024 20:52:52 -0600 Subject: [PATCH] Allow nil current values in trends I think I might've gotten it wrong before, nils might appear in trends if values are unavailable for snapshots --- app/models/time_series/trend.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/time_series/trend.rb b/app/models/time_series/trend.rb index 03fb2d3d..5c7bec18 100644 --- a/app/models/time_series/trend.rb +++ b/app/models/time_series/trend.rb @@ -8,7 +8,7 @@ class TimeSeries::Trend validate :values_must_be_of_same_type, :values_must_be_of_known_type def initialize(current:, previous:, series: nil) - @current = current || 0 + @current = current @previous = previous @series = series @@ -68,12 +68,12 @@ class TimeSeries::Trend end def values_must_be_of_known_type - unless current.is_a?(Money) || current.is_a?(Numeric) - errors.add :current, "must be of type Money or Numeric" + unless current.is_a?(Money) || current.is_a?(Numeric) || current.nil? + errors.add :current, "must be of type Money, Numeric, or nil" end unless previous.is_a?(Money) || previous.is_a?(Numeric) || previous.nil? - errors.add :previous, "must be of type Money, Numeric or nil" + errors.add :previous, "must be of type Money, Numeric, or nil" end end