class AccountBalance < ApplicationRecord belongs_to :account scope :in_period, ->(period) { period.date_range.nil? ? all : where(date: period.date_range) } def self.to_series(account, period = Period.all) MoneySeries.new( in_period(period).order(:date), { trend_type: account.classification } ) end end