From a74a5e1090dd88d2c350b29f29e51d9ddd4f676f Mon Sep 17 00:00:00 2001 From: Andrew Williams Date: Sun, 20 Apr 2014 00:13:11 +0100 Subject: [PATCH] Rework handling to a generic Entity class, add Payees. --- pynab/budget.py | 44 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/pynab/budget.py b/pynab/budget.py index 206f588..db083b9 100644 --- a/pynab/budget.py +++ b/pynab/budget.py @@ -4,20 +4,43 @@ import locale from pynab.exceptions import InvalidBudget -class Category(object): - pass +class Entity(dict): + def __repr__(self): + return u'<{}>'.format(self.__unicode__()) -class Account(dict): + def __unicode__(self): + return u'{} ({})'.format(self.name, self.type) @property def id(self): return self['entityId'] + @property + def type(self): + return self['entityType'] + + @property + def version(self): + return self['entityVersion'] + @property def name(self): return self['name'] + +class Category(Entity): + """ + YNAB Budget Category + """ + pass + + +class Account(Entity): + """ + YNAB Account + """ + @property def account_type(self): return self['accountType'] @@ -37,11 +60,11 @@ class Account(dict): def __unicode__(self): return u'{} ({})'.format(self['accountName'], self['accountType']) - def __repr__(self): - return u'<{}>'.format(self.__unicode__()) - class Budget(object): + """ + YNAB Budget + """ def __init__(self, filename=None): self._data = None @@ -77,7 +100,7 @@ class Budget(object): @property def budget_type(self): """ - Returnt the budget type + Returns the budget type """ if self._data: return self._data['budgetMetaData']['budgetType'] @@ -100,4 +123,11 @@ class Budget(object): @property def accounts(self): + """ + Returns all the accounts stored in the Budget + """ return [Account(account) for account in self._data['accounts']] + + @property + def payees(self): + return [Entity(payee) for payee in self._data['payees']] \ No newline at end of file