1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-08-04 21:15:19 +02:00

Vehicle view (#1117)

This commit is contained in:
Zach Gollwitzer 2024-08-23 09:33:42 -04:00 committed by GitHub
parent e856691c86
commit 359bceb58e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 259 additions and 8 deletions

View file

@ -3,7 +3,7 @@ class Measurement
attr_reader :value, :unit
VALID_UNITS = %w[sqft sqm]
VALID_UNITS = %w[sqft sqm mi km]
validates :unit, inclusion: { in: VALID_UNITS }
validates :value, presence: true

View file

@ -15,10 +15,6 @@ class Property < ApplicationRecord
first_valuation_amount
end
def equity_value
account.balance_money
end
def trend
TimeSeries::Trend.new(current: account.balance_money, previous: first_valuation_amount)
end

View file

@ -1,3 +1,22 @@
class Vehicle < ApplicationRecord
include Accountable
attribute :mileage_unit, :string, default: "mi"
def mileage
Measurement.new(mileage_value, mileage_unit) if mileage_value.present?
end
def purchase_price
first_valuation_amount
end
def trend
TimeSeries::Trend.new(current: account.balance_money, previous: first_valuation_amount)
end
private
def first_valuation_amount
account.entries.account_valuations.order(:date).first&.amount_money || account.balance_money
end
end