diff --git a/src/ledger/balances.go b/src/ledger/balances.go index 01533a5..89ca093 100644 --- a/src/ledger/balances.go +++ b/src/ledger/balances.go @@ -11,6 +11,17 @@ type Balances map[string]Balance type Balance map[Currency]float64 +func (balances Balances) NotLike(pattern string) Balances { + result := make(Balances) + p := regexp.MustCompile(pattern) + for k, v := range balances { + if !p.MatchString(k) { + result[k] = maps.Clone(v) + } + } + return result +} + func (balances Balances) Like(pattern string) Balances { result := make(Balances) p := regexp.MustCompile(pattern) diff --git a/src/ledger/balances_test.go b/src/ledger/balances_test.go index 1356b77..84b26da 100644 --- a/src/ledger/balances_test.go +++ b/src/ledger/balances_test.go @@ -61,6 +61,11 @@ func TestBalances(t *testing.T) { if len(got) != 1 || got["ab"][USD] != 1.2 { t.Error(got) } + + got = was.NotLike(`^ab$`) + if len(got) != 1 || got["a"][USD] != 0.1 { + t.Error(got) + } }) t.Run("group", func(t *testing.T) { diff --git a/src/ledger/like.go b/src/ledger/like.go index 3967932..cba6b6a 100644 --- a/src/ledger/like.go +++ b/src/ledger/like.go @@ -8,12 +8,21 @@ type Like func(Delta) bool type Likes []Like -func LikeTransaction(delta Delta) Like { +func LikeTransactions(deltas ...Delta) Like { return func(d Delta) bool { - return d.Transaction == delta.Transaction + for i := range deltas { + if deltas[i].Transaction == d.Transaction { + return true + } + } + return false } } +func LikeTransaction(delta Delta) Like { + return LikeTransactions(delta) +} + func LikeBefore(date string) Like { return func(d Delta) bool { return date >= d.Date