From c14ac56a32a77a45bf1a5aaf20e41c86fcef5548 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Thu, 15 Aug 2013 19:38:48 -0400 Subject: [PATCH] Account: cache full name instead of recalculating it every time --- lib/gnucash/account.rb | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/gnucash/account.rb b/lib/gnucash/account.rb index 0251371..58ac448 100644 --- a/lib/gnucash/account.rb +++ b/lib/gnucash/account.rb @@ -32,14 +32,7 @@ module Gnucash # Return the fully qualified account name def full_name - prefix = "" - if @parent_id - parent = @book.find_account_by_id(@parent_id) - if parent and parent.type != 'ROOT' - prefix = parent.full_name + "::" - end - end - prefix + name + @full_name ||= calculate_full_name end # Internal method used to associate a transaction with the account @@ -87,5 +80,18 @@ module Gnucash end @balances[idx][:value] end + + private + + def calculate_full_name + prefix = "" + if @parent_id + parent = @book.find_account_by_id(@parent_id) + if parent and parent.type != 'ROOT' + prefix = parent.full_name + "::" + end + end + prefix + name + end end end