Documentation ¶
Overview ¶
Package categories maintains metadata on spending categories.
Index ¶
- Variables
- type AccountAdder
- type AccountDetail
- type AccountDetailConsumer
- type AccountRemover
- type AccountUpdater
- type CatDbRow
- type CatDetail
- type CatDetailConsumer
- type CatDetailStore
- func (cds CatDetailStore) AccountAdd(name string, adder AccountAdder) (updatedStore CatDetailStore, newId int64, err error)
- func (cds CatDetailStore) AccountDetailById(id int64) AccountDetail
- func (cds CatDetailStore) AccountDetailByName(name string) (accountDetail AccountDetail, exists bool)
- func (cds CatDetailStore) AccountRemove(id int64, remover AccountRemover) (updatedStore CatDetailStore, err error)
- func (cds CatDetailStore) AccountRename(id int64, name string, updater AccountUpdater) (updatedStore CatDetailStore, err error)
- func (cds CatDetailStore) ActiveAccountDetails() []AccountDetail
- func (cds CatDetailStore) ActiveCatDetails(accounts bool) []CatDetail
- func (cds CatDetailStore) Add(name string, adder CategoryAdder) (updatedStore CatDetailStore, newId fin.Cat, err error)
- func (cds CatDetailStore) DetailByFullName(fullName string) (catDetail CatDetail, exists bool)
- func (cds CatDetailStore) DetailById(cat fin.Cat) CatDetail
- func (cds CatDetailStore) DetailsByIds(cats fin.CatSet) []CatDetail
- func (cds CatDetailStore) Filter(cat fin.Cat, includeChildren bool) fin.CatFilter
- func (cds CatDetailStore) ImmediateParent(cat fin.Cat) fin.Cat
- func (cds CatDetailStore) InactiveDetailByFullName(fullName string) (catDetail CatDetail, exists bool)
- func (cds CatDetailStore) IsChildOf(childCat, parentCat fin.Cat) bool
- func (cds CatDetailStore) LeafNameById(cat fin.Cat) string
- func (cds CatDetailStore) PurgeableAccounts(accountSet fin.AccountSet) fin.AccountSet
- func (cds CatDetailStore) PurgeableCats(total fin.CatTotals) fin.CatSet
- func (cds CatDetailStore) Remove(cat fin.Cat, remover CategoryRemover) (updatedStore CatDetailStore, err error)
- func (cds CatDetailStore) Rename(id fin.Cat, newName string, updater CategoryUpdater) (updatedStore CatDetailStore, err error)
- func (cds CatDetailStore) RollUp(totals fin.CatTotals) (rolledUp fin.CatTotals, children map[fin.Cat]fin.CatSet)
- func (cds CatDetailStore) SortedCatRecs(catrecs []fin.CatRec) []fin.CatRec
- type CatDetailStoreBuilder
- type CategoryAdder
- type CategoryRemover
- type CategoryUpdater
- type NamedCat
Constants ¶
This section is empty.
Variables ¶
var ( MalformedCategoryName = errors.New("categories: Malformed catgory name") NoParentCategory = errors.New("categories: No parent category") NoSuchCategory = errors.New("categories: No such category") NeedExpenseIncomeCategory = errors.New("categories: Need expense/income category") InvalidRename = errors.New("categories: Invalid rename") InvalidRenameWouldCauseCycle = errors.New("categories: Rename would cause a cycle.") DuplicateCategoryName = errors.New("categories: Duplicate category name.") )
Functions ¶
This section is empty.
Types ¶
type AccountAdder ¶
AccountAdder adds a new account to the database. name is the name of the account.
type AccountDetail ¶
type AccountDetail struct {
// contains filtered or unexported fields
}
AccountDetail represents account detail.
func (AccountDetail) Active ¶
func (a AccountDetail) Active() bool
Active returns true if account is active.
type AccountDetailConsumer ¶
type AccountDetailConsumer struct { // Builder is what is being populated Builder *CatDetailStoreBuilder }
AccountDetailConsumer populates a CatDetailStoreBuilder value with accounts.
func (*AccountDetailConsumer) CanConsume ¶
func (c *AccountDetailConsumer) CanConsume() bool
func (*AccountDetailConsumer) Consume ¶
func (c *AccountDetailConsumer) Consume(account fin.Account)
type AccountRemover ¶
AccountRemover removes a account in the database by marking it inactive.
type AccountUpdater ¶
AccountUpdater updates a account in the database
type CatDetail ¶
type CatDetail struct {
// contains filtered or unexported fields
}
CatDetail represents category detail.
func MostPopularFirst ¶
func MostPopularFirst( catDetails []CatDetail, catPopularity fin.CatPopularity, mostPopularRatio float64, maxMostPopularCount int) []CatDetail
MostPopularFirst returns catDetails prepended with the most popular categories followed by the least popular categories. MostPopularFirst prepends len(catDetails)*mostPopularRatio categories, but will not prepend more than maxMostPopularCount categories if maxMostPopularCount is >= 0. Categories with a popularity of 0 are never prepended.
type CatDetailConsumer ¶
type CatDetailConsumer struct { // Builder is what is being populated Builder *CatDetailStoreBuilder // Type is either fin.ExpenseCat or fin.IncomeCat. Type fin.CatType }
CatDetailConsumer populates a CatDetailStoreBuilder value with CatDbRow values.
func (*CatDetailConsumer) CanConsume ¶
func (c *CatDetailConsumer) CanConsume() bool
func (*CatDetailConsumer) Consume ¶
func (c *CatDetailConsumer) Consume(row CatDbRow)
type CatDetailStore ¶
type CatDetailStore struct {
// contains filtered or unexported fields
}
CatDetailStore contains all information on categories. The zero value of CatDetailStore contains only the trivial categories, "expense" and "income," and no accounts.
func (CatDetailStore) AccountAdd ¶
func (cds CatDetailStore) AccountAdd(name string, adder AccountAdder) ( updatedStore CatDetailStore, newId int64, err error)
AccountAdd adds a new account in the database and returns the updated store. Name is the name of the new account; adder adds the account to the database. On error, returns the receiver unchanged.
func (CatDetailStore) AccountDetailById ¶
func (cds CatDetailStore) AccountDetailById(id int64) AccountDetail
AccountDetailById returns account details by acount Id.
func (CatDetailStore) AccountDetailByName ¶
func (cds CatDetailStore) AccountDetailByName(name string) (accountDetail AccountDetail, exists bool)
AccountDetailByName returns account detail by account name. If no such account exists or is inactive, then exists is false.
func (CatDetailStore) AccountRemove ¶
func (cds CatDetailStore) AccountRemove( id int64, remover AccountRemover) ( updatedStore CatDetailStore, err error)
AccountRemove removes a account from database and returns the updated store. id specifies the account to be removed; remover does the actual remove in the database. On error, returns the receiver unchanged.
func (CatDetailStore) AccountRename ¶
func (cds CatDetailStore) AccountRename( id int64, name string, updater AccountUpdater) ( updatedStore CatDetailStore, err error)
AccountRename renames an account in the database and returns the updated store. id is the id of the account to be renamed; newName is the new name; updater does the rename in the database. On error, returns the receiver unchanged. If id represents an inactive account, it is made active when renamed.
func (CatDetailStore) ActiveAccountDetails ¶
func (cds CatDetailStore) ActiveAccountDetails() []AccountDetail
ActiveAccountDetails returns all active details sorted by name.
func (CatDetailStore) ActiveCatDetails ¶
func (cds CatDetailStore) ActiveCatDetails(accounts bool) []CatDetail
ActiveCatDetails returns all active category details sorted by full name. If accounts is true also includes account categories.
func (CatDetailStore) Add ¶
func (cds CatDetailStore) Add(name string, adder CategoryAdder) ( updatedStore CatDetailStore, newId fin.Cat, err error)
Add adds a new category in the database and returns the updated store. Name is the full name of the new category; adder adds the category to the database. On error, returns the receiver unchanged.
func (CatDetailStore) DetailByFullName ¶
func (cds CatDetailStore) DetailByFullName(fullName string) (catDetail CatDetail, exists bool)
DetailByFullName returns details by category full name. If no such category exists or is inactive, then exists is false.
func (CatDetailStore) DetailById ¶
func (cds CatDetailStore) DetailById(cat fin.Cat) CatDetail
DetailById returns details by category Id.
func (CatDetailStore) DetailsByIds ¶
func (cds CatDetailStore) DetailsByIds(cats fin.CatSet) []CatDetail
DetailsByIds returns details sorted by full name for selected categories.
func (CatDetailStore) Filter ¶
Filter returns a CatFilter for finding entries under a specific category.
func (CatDetailStore) ImmediateParent ¶
func (cds CatDetailStore) ImmediateParent(cat fin.Cat) fin.Cat
ImmediateParent returns the immediate parent category of given category. If given category is already top level, returns the same top level category.
func (CatDetailStore) InactiveDetailByFullName ¶
func (cds CatDetailStore) InactiveDetailByFullName(fullName string) ( catDetail CatDetail, exists bool)
InactiveDetailByFullName returns details for inactive categories by category full name that can be made active again. If no such category exists or is active, or can't be made active because it has some ancestor category that is inactive then exists is false.
func (CatDetailStore) IsChildOf ¶
func (cds CatDetailStore) IsChildOf(childCat, parentCat fin.Cat) bool
IsChildOf returns true if childCat is a child of parentCat.
func (CatDetailStore) LeafNameById ¶
func (cds CatDetailStore) LeafNameById(cat fin.Cat) string
LeafNameById returns the category leaf name by category Id.
func (CatDetailStore) PurgeableAccounts ¶
func (cds CatDetailStore) PurgeableAccounts( accountSet fin.AccountSet) fin.AccountSet
PurgeableAccounts returns account ids eligible for purging. An account is eligible for purging it it is inactive and not used in any entry. accountSet should include the account ids used in all entries in the data store.
func (CatDetailStore) PurgeableCats ¶
func (cds CatDetailStore) PurgeableCats(total fin.CatTotals) fin.CatSet
PurgeableCats returns category ids eligible for purging. A category is eligible for purging it it is inactive and it nor any of its children are used in any entry. total should include totals for all entries in the data store. PurgeableCats calls RollUp on total internally. PurgeableCats will only return expense and income categories.
func (CatDetailStore) Remove ¶
func (cds CatDetailStore) Remove( cat fin.Cat, remover CategoryRemover) ( updatedStore CatDetailStore, err error)
Remove removes a category form database and returns the updated store. cat specifies the category to be removed; remover does the actual remove in the database. On error, returns the receiver unchanged.
func (CatDetailStore) Rename ¶
func (cds CatDetailStore) Rename(id fin.Cat, newName string, updater CategoryUpdater) ( updatedStore CatDetailStore, err error)
Rename renames a category in the database and returns the updated store. id is the id of the category to be renamed; newName is the new name; updater does the rename in the database. On error, returns the receiver unchanged. If id represents an inactive category, it is made active when renamed.
func (CatDetailStore) RollUp ¶
func (cds CatDetailStore) RollUp(totals fin.CatTotals) (rolledUp fin.CatTotals, children map[fin.Cat]fin.CatSet)
RollUp rolls totals from child categories into parent categories. The children return value contains the immediate child categories that were rolled into each parent category.
func (CatDetailStore) SortedCatRecs ¶
func (cds CatDetailStore) SortedCatRecs(catrecs []fin.CatRec) []fin.CatRec
SortedCatRecs sorts catrecs by category full name and returns catrecs.
type CatDetailStoreBuilder ¶
type CatDetailStoreBuilder struct {
// contains filtered or unexported fields
}
CatDetailsStoreBuilder is used to initialize CatDetailStore values.
func (*CatDetailStoreBuilder) AddAccount ¶
func (cdsb *CatDetailStoreBuilder) AddAccount( account *fin.Account) *CatDetailStoreBuilder
AddAccount adds an account.
func (*CatDetailStoreBuilder) AddCatDbRow ¶
func (cdsb *CatDetailStoreBuilder) AddCatDbRow( t fin.CatType, row *CatDbRow) *CatDetailStoreBuilder
AddCatDbRow adds expense or income category depending on t. t is either fin.ExpenseCat or fin.IncomeCat.
func (*CatDetailStoreBuilder) Build ¶
func (cdsb *CatDetailStoreBuilder) Build() CatDetailStore
Build returns a new CatDetailStore and resets this builder.
type CategoryAdder ¶
CategoryAdder adds a new category to the database. t is fin.ExpenseCat or fin.IncomeCat. row is the category to be added.
type CategoryRemover ¶
CategoryRemover removes a category in the database by marking it inactive. t is fin.ExpenseCat or fin.IncomeCat. id specifies what is to be deleted.
type CategoryUpdater ¶
CategoryUpdater updates a category in the database t is fin.ExpenseCat or fin.IncomeCat. row denotes the updated category.
type NamedCat ¶
NamedCat represents a category Id and name
func Ancestors ¶
func Ancestors(cds CatDetailStore, cat fin.Cat) []NamedCat
Ancestors returns all the ancestor categories of cat. The first item in returned slice is always one of the top level categories; the last item is always cat. The items in between are the other ancestor categories of cat with the most distant ones coming first. The name in each returned category is that category's leaf name.
Directories ¶
Path | Synopsis |
---|---|
Package categoriesdb contains the persistence layer for the categories package.
|
Package categoriesdb contains the persistence layer for the categories package. |
fixture
Package fixture provides test suites to test implementations of the interfaces in the categoriesdb package.
|
Package fixture provides test suites to test implementations of the interfaces in the categoriesdb package. |
for_sqlite
Package for_sqlite stores types in categories package in a sqlite database.
|
Package for_sqlite stores types in categories package in a sqlite database. |