Last active
March 31, 2024 00:03
-
-
Save pdx91/1c82640957732d454ef5a6af262b2c46 to your computer and use it in GitHub Desktop.
BalanceHistory::Preservation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This class in pulled from https://balance.day for my 37signals application. | |
class BalanceHistory::Preservation | |
InvalidData = Class.new(StandardError) | |
attr_reader :account | |
def initialize(account) | |
@account = account | |
end | |
def preserve! | |
strategy.perform! | |
end | |
private | |
def strategy | |
if investment_account? && investment_strategy_enabled? | |
Strategy::PortfolioValue.new(account) | |
else | |
Strategy::AccountBalance.new(account) | |
end | |
end | |
def investment_account? | |
account.account_type.investment? && account.holdings.present? | |
end | |
def investment_strategy_enabled? | |
System.investments_enabled?(account.user) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment