rules

package
v0.8.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 18, 2021 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Default is the set of rules applied to incoming transaction, always
	Default = Rules{
		category{Negative: true, Category: "expenses:uncategorized"},
		category{
			PayeeContains: containsPattern(
				"'s",
				".*vend.*",
				"airport",
				"american",
				"bagels?",
				"bakery",
				"bar",
				"barbecue",
				"bbq",
				"bean",
				"beverage",
				"bistro",
				"bowl",
				"burger.*",
				"cafe",
				"caffe",
				"candy",
				"catering",
				"chicken",
				"coffee",
				"coffeehouse",
				"cola",
				"counter",
				"cream",
				"crepe",
				"cuisine",
				"custard",
				"deli",
				"diner",
				"donuts?",
				"drive",
				"food",
				"french",
				"gelato",
				"gourmet",
				"grill",
				"house",
				"indian",
				"italian",
				"japanese",
				"juice",
				"kitchen",
				"lunch.*",
				"market",
				"noodle",
				"pasta",
				"pie",
				"pies",
				"pizza",
				"pizzeria",
				"pot",
				"ramen",
				"restaurant",
				"rice",
				"sandwich",
				"shake",
				"shop",
				"snack",
				"soda",
				"soup",
				"spot",
				"stand",
				"sushi",
				"taco",
				"thai",
				"tortilla",
			),
			Negative: true,
			Category: "expenses:shopping:food:restaurants",
		},
		category{Positive: true, Category: "revenues:uncategorized"},
		category{
			PayeeContains: containsPattern(
				"autodiv",
				"dividend",
				"int",
				"interest",
			),
			Positive: true,
			Category: "revenues:interest",
		},
		category{
			PayeeContains: containsPattern(
				"check",
				"deposit",
			),
			Positive: true,
			Category: "revenues:deposits",
		},
		category{
			PayeeContains: containsPattern(
				"transfer",
				"wire",
			),
			Category: "expenses:transfers",
		},
		category{
			PayeeContains: containsPattern(
				"irs",
				"us treasury",
			),
			Positive: true,
			Category: "revenues:tax returns",
		},
		category{
			PayeeContains: containsPattern(
				"dental",
				"optometrist",
				"medical",
			),
			Negative: true,
			Category: "expenses:health",
		},
		category{
			PayeeContains: containsPattern(
				"city",
				"grande",
				"spectrum",
				"comcast",
			),
			Negative: true,
			Category: "expenses:home:utilities",
		},
		category{
			PayeeContains: containsPattern(
				".*\\.com?",
				"amazon",
				"amzn",
				"barnes.*noble",
				"books?",
				"cvs",
				"e-commerce",
				"gift",
				"hallmark",
				"ikea",
				"photo.*",
				"sq \\*",
				"staples",
				"walgreens",
			),
			Negative: true,
			Category: "expenses:shopping",
		},
		category{
			PayeeContains: containsPattern(
				"apple",
				"best buy",
				"computers?",
				"dell",
				"drop",
				"electronics",
				"fry's",
				"gamestop",
				"massdrop",
				"newegg.com",
				"software",
				"steamgames.com",
				"steampowered.com",
				"texas instruments",
			),
			Negative: true,
			Category: "expenses:shopping:electronics",
		},
		category{
			PayeeContains: containsPattern(
				"apple music",
				"audible",
				"codeschool.com",
				"godaddy.com",
				"itunes.com/bill",
				"membership",
				"name-cheap.com",
				"pandora",
				"spotify",
				"subscriptions?",
			),
			Negative: true,
			Category: "expenses:shopping:subscriptions",
		},
		category{
			PayeeContains: containsPattern(
				"7-eleven",
				"chevron",
				"exxon.*",
				"shell",
			),
			Negative: true,
			Category: "expenses:car:gas",
		},
		category{
			PayeeContains: containsPattern(
				"vehreg",
				"dps",
			),
			Negative: true,
			Category: "expenses:car:registration",
		},
		category{
			PayeeContains: containsPattern(
				"autopay",
				"directpay",
				"e-?payment",
				"internet payment",
			),
			Category: "expenses:transfers:credit card payments",
		},
		category{
			PayeeContains: containsPattern(
				"alamo",
				"amc",
				"cinema",
				"cinemark",
				"conv center",
				"fandango.com",
				"fgt\\*",
				"stubhub",
				"ticketfly",
				"tickets?",
			),
			Negative: true,
			Category: "expenses:concerts and shows",
		},
		category{
			PayeeContains: containsPattern(
				"heb",
				"h-e-b",
				"wal-mart",
				"supercenter",
				"wholefds",
				"mart",
				"market",
				"safeway",
				"grocer",
				"liquor",
			),
			Negative: true,
			Category: "expenses:shopping:food:groceries",
		},
	}
)

Functions

This section is empty.

Types

type Rule

type Rule interface {
	Match(ledger.Transaction) bool
	Apply(*ledger.Transaction)
}

Rule can match a transaction and apply a transformation to it

func NewCSVRule

func NewCSVRule(account1, account2, comment string, conditions ...string) (Rule, error)

type Rules

type Rules []Rule

Rules enables transformation of transactions across multiple, sequential rules

func NewCSVRulesFromReader

func NewCSVRulesFromReader(reader io.Reader) (Rules, error)

func (Rules) Apply

func (r Rules) Apply(txn *ledger.Transaction)

Apply runs a match and subsequent apply for each rule on the given transaction

func (Rules) Matches added in v0.8.0

func (r Rules) Matches(txn *ledger.Transaction) map[int]Rule

Matches returns matching rules

func (Rules) String

func (r Rules) String() string

func (*Rules) UnmarshalJSON added in v0.3.0

func (r *Rules) UnmarshalJSON(b []byte) error

UnmarshalJSON parses the given bytes into rules

type Store added in v0.3.0

type Store struct {
	// contains filtered or unexported fields
}

Store enables manipulation of rules in memory

func NewStore added in v0.3.0

func NewStore(rules Rules) *Store

NewStore creates a rules store from the given rules

func (*Store) Accounts added in v0.4.0

func (s *Store) Accounts() []string

Accounts returns account names (account2) for any CSV rules

func (*Store) Add added in v0.8.0

func (s *Store) Add(rule Rule) (newRuleIndex int)

Add appends a new rule

func (*Store) Apply added in v0.3.0

func (s *Store) Apply(txn *ledger.Transaction)

Apply transforms the given transaction based on the current rules

func (*Store) ApplyAll added in v0.3.0

func (s *Store) ApplyAll(txns []ledger.Transaction)

ApplyAll transforms the given transactions based on the current rules and the default rules. Custom rules take precedence to default rules.

func (*Store) Get added in v0.8.0

func (s *Store) Get(index int) (Rule, error)

Get returns the rule at 'index'

func (*Store) MarshalJSON added in v0.3.0

func (s *Store) MarshalJSON() ([]byte, error)

MarshalJSON returns JSON-encoded rules

func (*Store) Matches added in v0.8.0

func (s *Store) Matches(txn *ledger.Transaction) map[int]Rule

Matches returns matching rules

func (*Store) Remove added in v0.8.0

func (s *Store) Remove(index int) error

Remove removes the rule at 'index'

func (*Store) Replace added in v0.3.0

func (s *Store) Replace(newRules Rules)

Replace replaces the current rules with newRules

func (*Store) String added in v0.3.0

func (s *Store) String() string

func (*Store) Update added in v0.8.0

func (s *Store) Update(index int, rule Rule) error

Update updates the rule at 'index' with 'rule'

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL