1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-08-09 15:35:22 +02:00

Implement better mapping

This commit is contained in:
hatz 2025-04-21 13:32:33 -05:00
parent d9f78b167e
commit 24d4e09ef3
No known key found for this signature in database
4 changed files with 15 additions and 23 deletions

View file

@ -3,26 +3,4 @@ module AccountsHelper
content = capture(&block)
render "accounts/summary_card", title: title, content: content
end
# Format account subtype to be more friendly
def format_account_subtype(subtype)
return nil if subtype.nil?
# Mapping of special cases
special_cases = {
"ira" => "IRA",
"401k" => "401(k)",
"hsa" => "HSA"
}
# Convert to title case
subtype_string = subtype.titleize
special_cases.each do |key, value|
# Use word boundaries to ensure we're replacing whole words
subtype_string = subtype_string.gsub(/\b#{key}\b/i, value)
end
subtype_string
end
end

View file

@ -59,6 +59,12 @@ class BalanceSheet
account.define_singleton_method(:weight) do
classification_total.zero? ? 0 : account.converted_balance / classification_total.to_d * 100
end
# Define our subtype labeling logic
account.define_singleton_method(:subtype_label) do
accountable.subtype_label_for(account.subtype) || accountable.display_name
end
account
end.sort_by(&:weight).reverse
)

View file

@ -2,6 +2,9 @@ module Accountable
extend ActiveSupport::Concern
TYPES = %w[Depository Investment Crypto Property Vehicle OtherAsset CreditCard Loan OtherLiability]
# Define empty array to ensure all accountables have this defined
SUBTYPES = []
def self.from_type(type)
return nil unless TYPES.include?(type)
@ -27,6 +30,11 @@ module Accountable
raise NotImplementedError, "Accountable must implement #color"
end
# Given a subtype, look up the "label" for this accountable type
def subtype_label_for(subtype)
self::SUBTYPES.find { |subtype_label, subtype_value| subtype_value == subtype }&.first
end
def favorable_direction
classification == "asset" ? "up" : "down"
end

View file

@ -24,7 +24,7 @@
<div class="min-w-0 grow">
<%= tag.p account.name, class: "text-sm text-primary font-medium mb-0.5 truncate" %>
<%= tag.p format_account_subtype(account.subtype).presence || account_group.name, class: "text-sm text-secondary truncate" %>
<%= tag.p account.subtype_label, class: "text-sm text-secondary truncate" %>
</div>
<div class="ml-auto text-right grow h-10">