From a5346c7796c1ada2cbb275179740f60a6c31bf2f Mon Sep 17 00:00:00 2001 From: Chris Berkhout Date: Sun, 30 May 2021 14:27:13 +0200 Subject: [PATCH] Extract helper method. --- src/pricehist/outputs/gnucashsql.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/pricehist/outputs/gnucashsql.py b/src/pricehist/outputs/gnucashsql.py index 012901b..8329785 100644 --- a/src/pricehist/outputs/gnucashsql.py +++ b/src/pricehist/outputs/gnucashsql.py @@ -31,9 +31,7 @@ class GnuCashSQL(BaseOutput): ).encode("utf-8") ) guid = m.hexdigest()[0:32] - # TODO extract this logic to a helper method - value_num = str(price.amount).replace(".", "") - value_denom = 10 ** len(f"{price.amount}.".split(".")[1]) + value_num, value_denom = self._fractional(price.amount) v = ( "(" f"'{guid}', " @@ -58,3 +56,8 @@ class GnuCashSQL(BaseOutput): ) return sql + + def _fractional(num): + num = str(num).replace(".", "") + denom = 10 ** len(f"{num}.".split(".")[1]) + return (num, denom)