1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-19 21:29:38 +02:00
Maybe/app/models/security.rb

20 lines
496 B
Ruby
Raw Normal View History

class Security < ApplicationRecord
before_save :upcase_ticker
has_many :trades, dependent: :nullify, class_name: "Account::Trade"
validates :ticker, presence: true, uniqueness: { case_sensitive: false }
def current_price
@current_price ||= Security::Price.find_price(ticker:, date: Date.current)
return nil if @current_price.nil?
Money.new(@current_price.price, @current_price.currency)
end
private
def upcase_ticker
self.ticker = ticker.upcase
end
end