hledger-lib-1.41: A library providing the core functionality of hledger

Safe Haskell | None
Language | Haskell2010

Hledger.Data.AccountName

Description

`AccountName`s are strings like `assets:cash:petty`, with multiple components separated by `:`. From a set of these we derive the account hierarchy.

Synopsis

- accountLeafName :: AccountName -> Text
- accountNameComponents :: AccountName -> [Text]
- accountNameDrop :: Int -> AccountName -> AccountName
- accountNameFromComponents :: [Text] -> AccountName
- accountNameLevel :: AccountName -> Int
- accountNameToAccountOnlyRegex :: AccountName -> Regexp
- accountNameToAccountOnlyRegexCI :: AccountName -> Regexp
- accountNameToAccountRegex :: AccountName -> Regexp
- accountNameToAccountRegexCI :: AccountName -> Regexp
- accountNameTreeFrom :: [AccountName] -> Tree AccountName
- accountSummarisedName :: AccountName -> Text
- accountNameInferType :: AccountName -> Maybe AccountType
- accountNameInferTypeExcept :: [AccountType] -> AccountName -> Maybe AccountType
- accountNameType :: Map AccountName AccountType -> AccountName -> Maybe AccountType
- defaultBaseConversionAccount :: IsString a => a
- assetAccountRegex :: Regexp
- cashAccountRegex :: Regexp
- liabilityAccountRegex :: Regexp
- equityAccountRegex :: Regexp
- conversionAccountRegex :: Regexp
- revenueAccountRegex :: Regexp
- expenseAccountRegex :: Regexp
- acctsep :: Text
- acctsepchar :: Char
- clipAccountName :: DepthSpec -> AccountName -> AccountName
- clipOrEllipsifyAccountName :: DepthSpec -> AccountName -> AccountName
- getAccountNameClippedDepth :: DepthSpec -> AccountName -> Maybe Int
- elideAccountName :: Int -> AccountName -> AccountName
- escapeName :: AccountName -> Text
- expandAccountName :: AccountName -> [AccountName]
- expandAccountNames :: [AccountName] -> [AccountName]
- isAccountNamePrefixOf :: AccountName -> AccountName -> Bool
- isSubAccountNameOf :: AccountName -> AccountName -> Bool
- parentAccountName :: AccountName -> AccountName
- parentAccountNames :: AccountName -> [AccountName]
- subAccountNamesFrom :: [AccountName] -> AccountName -> [AccountName]
- topAccountNames :: [AccountName] -> [AccountName]
- topAccountName :: AccountName -> AccountName
- unbudgetedAccountName :: Text
- accountNamePostingType :: AccountName -> PostingType
- accountNameWithoutPostingType :: AccountName -> AccountName
- accountNameWithPostingType :: PostingType -> AccountName -> AccountName
- joinAccountNames :: AccountName -> AccountName -> AccountName
- concatAccountNames :: [AccountName] -> AccountName
- accountNameApplyAliases :: [AccountAlias] -> AccountName -> Either RegexError AccountName
- accountNameApplyAliasesMemo :: [AccountAlias] -> AccountName -> Either RegexError AccountName
- tests_AccountName :: TestTree

# Documentation

accountLeafName :: AccountName -> Text #

accountNameComponents :: AccountName -> [Text] #

accountNameDrop :: Int -> AccountName -> AccountName #

Remove some number of account name components from the front of the account name. If the special "unbudgeted" top-level account is present, it is preserved and dropping affects the rest of the account name.

accountNameFromComponents :: [Text] -> AccountName #

accountNameLevel :: AccountName -> Int #

The level (depth) of an account name.

    >>> accountNameLevel ""  -- special case
    0
    >>> accountNameLevel "assets"
    1
    >>> accountNameLevel "assets:cash"
    2

accountNameToAccountOnlyRegex :: AccountName -> Regexp #

Convert an account name to a regular expression matching it but not its subaccounts.

accountNameToAccountOnlyRegexCI :: AccountName -> Regexp #

Convert an account name to a regular expression matching it but not its subaccounts, case insensitively.

accountNameToAccountRegex :: AccountName -> Regexp #

Convert an account name to a regular expression matching it and its subaccounts.

accountNameToAccountRegexCI :: AccountName -> Regexp #

Convert an account name to a regular expression matching it and its subaccounts, case insensitively.

accountNameTreeFrom :: [AccountName] -> Tree AccountName #

Convert a list of account names to a tree, efficiently.

accountSummarisedName :: AccountName -> Text #

Truncate all account name components but the last to two characters.

accountNameInferType :: AccountName -> Maybe AccountType #

Try to guess an account's type from its name, matching common English top-level account names.

accountNameInferTypeExcept :: [AccountType] -> AccountName -> Maybe AccountType #

Like accountNameInferType, but exclude the provided types from the guesses. Used eg to prevent "equity:conversion" being inferred as Conversion when a different account has been declared with that type.

accountNameType :: Map AccountName AccountType -> AccountName -> Maybe AccountType #

defaultBaseConversionAccount :: IsString a => a #

assetAccountRegex :: Regexp #

Regular expressions matching common English top-level account names, used as a fallback when account types are not declared.

cashAccountRegex :: Regexp #

liabilityAccountRegex :: Regexp #

equityAccountRegex :: Regexp #

conversionAccountRegex :: Regexp #

revenueAccountRegex :: Regexp #

expenseAccountRegex :: Regexp #

acctsep :: Text #

acctsepchar :: Char #

clipAccountName :: DepthSpec -> AccountName -> AccountName #

Clip an account name to a given `DepthSpec`, first checking whether it matches any of the regular expressions controlling depth. If so, clip to the depth of the most specific of those matches, i.e. the one which starts matching the latest as you progress up the parents of the account. Otherwise clip to the flat depth provided, or return the full name if Nothing.

clipOrEllipsifyAccountName :: DepthSpec -> AccountName -> AccountName #

As `clipAccountName`, but return `...` if asked to clip to depth 0.

getAccountNameClippedDepth :: DepthSpec -> AccountName -> Maybe Int #

Calculate the depth to which an account name should be clipped for a given `DepthSpec`.

First checking whether the account name matches any of the regular expressions controlling depth. If so, clip to the depth of the most specific of those matches, i.e. the one which starts matching the latest as you progress up the parents of the account. Otherwise clip to the flat depth provided, or return the full name if Nothing.

elideAccountName :: Int -> AccountName -> AccountName #

Elide an account name to fit in the specified width. From the ledger 2.6 news:

      What Ledger now does is that if an account name is too long, it will
      start abbreviating the first parts of the account name down to two
      letters in length.  If this results in a string that is still too
      long, the front will be elided -- not the end.  For example:

        Expenses:Cash           ; OK, not too long
        Ex:Wednesday:Cash       ; Expenses was abbreviated to fit
        Ex:We:Afternoon:Cash    ; Expenses and Wednesday abbreviated
        ; Expenses:Wednesday:Afternoon:Lunch:Snack:Candy:Chocolate:Cash
        ..:Af:Lu:Sn:Ca:Ch:Cash  ; Abbreviated and elided!

escapeName :: AccountName -> Text #

Escape an AccountName for use within a regular expression. >>> putStr . T.unpack $ escapeName "First?!#$*?$(*) !`^#*? %)*!`#" First?!#$*?$(*) !`^#*? %)*!`#

expandAccountName :: AccountName -> [AccountName] #

"a:b:c" -> ["a","a:b","a:b:c"]

expandAccountNames :: [AccountName] -> [AccountName] #

Sorted unique account names implied by these account names, ie these plus all their parent accounts up to the root. Eg: ["a:b:c","d:e"] -> ["a","a:b","a:b:c","d","d:e"]

isAccountNamePrefixOf :: AccountName -> AccountName -> Bool #

Is the first account a parent or other ancestor of (and not the same as) the second ?

isSubAccountNameOf :: AccountName -> AccountName -> Bool #

parentAccountName :: AccountName -> AccountName #

parentAccountNames :: AccountName -> [AccountName] #

subAccountNamesFrom :: [AccountName] -> AccountName -> [AccountName] #

From a list of account names, select those which are direct subaccounts of the given account name.

topAccountNames :: [AccountName] -> [AccountName] #

"a:b:c","d:e"
  -> ["a","d"]

topAccountName :: AccountName -> AccountName #

"a:b:c" -> "a"

unbudgetedAccountName :: Text #

A top-level account prefixed to some accounts in budget reports. Defined here so it can be ignored by accountNameDrop.

accountNamePostingType :: AccountName -> PostingType #

accountNameWithoutPostingType :: AccountName -> AccountName #

accountNameWithPostingType :: PostingType -> AccountName -> AccountName #

joinAccountNames :: AccountName -> AccountName -> AccountName #

Prefix one account name to another, preserving posting type indicators like concatAccountNames.

concatAccountNames :: [AccountName] -> AccountName #

Join account names into one. If any of them has () or [] posting type indicators, these (the first type encountered) will also be applied to the resulting account name.

accountNameApplyAliases :: [AccountAlias] -> AccountName -> Either RegexError AccountName #

Rewrite an account name using all matching aliases from the given list, in sequence. Each alias sees the result of applying the previous aliases. Or, return any error arising from a bad regular expression in the aliases.

accountNameApplyAliasesMemo :: [AccountAlias] -> AccountName -> Either RegexError AccountName #

Memoising version of accountNameApplyAliases, maybe overkill.

tests_AccountName :: TestTree #