mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-05 13:35:21 +02:00
Add nice formatting for subtypes on account list (#2138)
* Add nice formatting for subtypes on account list * Fix rubocop linting errors * Implement better mapping * Fix rubocop linting * Add short and long versions of subtypes * Simplify subtype reference Co-authored-by: Zach Gollwitzer <zach.gollwitzer@gmail.com> Signed-off-by: Alex Hatzenbuhler <hatz@hey.com> * Simplify reference logic, add a small test * Fix test * Fix tests --------- Signed-off-by: Alex Hatzenbuhler <hatz@hey.com> Co-authored-by: Zach Gollwitzer <zach.gollwitzer@gmail.com>
This commit is contained in:
parent
db34f6d7a2
commit
47aeaf8cea
12 changed files with 83 additions and 30 deletions
|
@ -3,6 +3,9 @@ module Accountable
|
|||
|
||||
TYPES = %w[Depository Investment Crypto Property Vehicle OtherAsset CreditCard Loan OtherLiability]
|
||||
|
||||
# Define empty hash to ensure all accountables have this defined
|
||||
SUBTYPES = {}.freeze
|
||||
|
||||
def self.from_type(type)
|
||||
return nil unless TYPES.include?(type)
|
||||
type.constantize
|
||||
|
@ -27,6 +30,24 @@ 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, format: :short)
|
||||
return nil if subtype.nil?
|
||||
|
||||
label_type = format == :long ? :long : :short
|
||||
self::SUBTYPES[subtype]&.fetch(label_type, nil)
|
||||
end
|
||||
|
||||
# Convenience method for getting the short label
|
||||
def short_subtype_label_for(subtype)
|
||||
subtype_label_for(subtype, format: :short)
|
||||
end
|
||||
|
||||
# Convenience method for getting the long label
|
||||
def long_subtype_label_for(subtype)
|
||||
subtype_label_for(subtype, format: :long)
|
||||
end
|
||||
|
||||
def favorable_direction
|
||||
classification == "asset" ? "up" : "down"
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue