mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-04 21:15:19 +02:00
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
This commit is contained in:
parent
ec68b9bfe7
commit
5d14d03963
1 changed files with 4 additions and 4 deletions
|
@ -8,7 +8,7 @@ class TimeSeries::Trend
|
||||||
validate :values_must_be_of_same_type, :values_must_be_of_known_type
|
validate :values_must_be_of_same_type, :values_must_be_of_known_type
|
||||||
|
|
||||||
def initialize(current:, previous:, series: nil)
|
def initialize(current:, previous:, series: nil)
|
||||||
@current = current || 0
|
@current = current
|
||||||
@previous = previous
|
@previous = previous
|
||||||
@series = series
|
@series = series
|
||||||
|
|
||||||
|
@ -68,12 +68,12 @@ class TimeSeries::Trend
|
||||||
end
|
end
|
||||||
|
|
||||||
def values_must_be_of_known_type
|
def values_must_be_of_known_type
|
||||||
unless current.is_a?(Money) || current.is_a?(Numeric)
|
unless current.is_a?(Money) || current.is_a?(Numeric) || current.nil?
|
||||||
errors.add :current, "must be of type Money or Numeric"
|
errors.add :current, "must be of type Money, Numeric, or nil"
|
||||||
end
|
end
|
||||||
|
|
||||||
unless previous.is_a?(Money) || previous.is_a?(Numeric) || previous.nil?
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue