From 58405fcdd8d7ebecaa80ecf12149e3c0aaa2f3e8 Mon Sep 17 00:00:00 2001 From: bel Date: Sun, 15 Oct 2023 11:25:54 -0600 Subject: [PATCH] implement transaction.go:Transaction:String with Amount:FormatUSD --- digits-work-sample-go.d/transaction.go | 20 ++++++++- todo.yaml | 60 +++++++++++++++++++++++--- 2 files changed, 72 insertions(+), 8 deletions(-) diff --git a/digits-work-sample-go.d/transaction.go b/digits-work-sample-go.d/transaction.go index 47b7424..dee1f46 100644 --- a/digits-work-sample-go.d/transaction.go +++ b/digits-work-sample-go.d/transaction.go @@ -3,6 +3,7 @@ package analyzer import ( "encoding/json" "errors" + "fmt" "os" ) @@ -23,8 +24,23 @@ type Transaction struct { } func (trn Transaction) String() string { - // TODO: Not implemented. - return "" + if trn.Amount < 0 { + return trn.stringifyRefund() + } + return trn.stringifyExpense() +} + +func (trn Transaction) stringifyRefund() string { + amount := trn.Amount * -1.0 + return fmt.Sprintf("%s refunded %s %s", trn.Vendor, trn.stringifyCardholder(), amount.FormatUSD()) +} + +func (trn Transaction) stringifyExpense() string { + return fmt.Sprintf("%s spent %s at %s", trn.stringifyCardholder(), trn.Amount.FormatUSD(), trn.Vendor) +} + +func (trn Transaction) stringifyCardholder() string { + return fmt.Sprintf("%s. %s", trn.CardholderFirstInitial, trn.CardholderLastName) } // Transactions represents a list of Transaction diff --git a/todo.yaml b/todo.yaml index bac4747..8fd05eb 100755 --- a/todo.yaml +++ b/todo.yaml @@ -2,12 +2,6 @@ todo: - review readme tail to finish // answer 3 questions, gofmt - todo: go test subtasks: - - my `go mod tidy` actually cleared `go.mod` file, probably weird localhost backwards - compatilble stuff - - TestTransaction_String - - TestTransaction_String/MCCOLLOMS_INC - - TestTransaction_String/QUANTUM_ELECTRIC_INC - - TestTransaction_String/MARRIOTT_33716_NEW_ORLEAN - TestAnalyzer_TransctionsSum - TestAnalyzer_LargestTransaction - TestAnalyzer_DuplicatesExcluded @@ -17,6 +11,10 @@ todo: - TestAnalyzer_TransactionsFromURLsConcurrent - amount.go:Rounded probably does NOT handle float precision well... it is float64 tho... + - my `go mod tidy` actually cleared `go.mod` file, probably weird localhost backwards + compatilble stuff + - transaction.go:Transaction:String not clear if FormatUSD or amount currency should + not be changed, or even what currency Amount is scheduled: [] done: - todo: hello world @@ -368,3 +366,53 @@ done: - amount.go:Rounded probably does NOT handle float precision well... it is float64 tho... ts: Sun Oct 15 11:19:11 MDT 2023 +- todo: go test + subtasks: + - my `go mod tidy` actually cleared `go.mod` file, probably weird localhost backwards + compatilble stuff + - TestTransaction_String + - TestTransaction_String/MCCOLLOMS_INC + - TestTransaction_String/QUANTUM_ELECTRIC_INC + - TestTransaction_String/MARRIOTT_33716_NEW_ORLEAN + - TestAnalyzer_TransctionsSum + - TestAnalyzer_LargestTransaction + - TestAnalyzer_DuplicatesExcluded + - TestAnalyzer_GroupByCategory + - TestAnalyzer_BigSpendersReport + - TestAnalyzer_TransactionsFromURLs + - TestAnalyzer_TransactionsFromURLsConcurrent + - amount.go:Rounded probably does NOT handle float precision well... it is float64 + tho... + ts: Sun Oct 15 11:19:20 MDT 2023 +- todo: go test + subtasks: + - TestTransaction_String + - TestTransaction_String/MCCOLLOMS_INC + - TestTransaction_String/QUANTUM_ELECTRIC_INC + - TestTransaction_String/MARRIOTT_33716_NEW_ORLEAN + - TestAnalyzer_TransctionsSum + - TestAnalyzer_LargestTransaction + - TestAnalyzer_DuplicatesExcluded + - TestAnalyzer_GroupByCategory + - TestAnalyzer_BigSpendersReport + - TestAnalyzer_TransactionsFromURLs + - TestAnalyzer_TransactionsFromURLsConcurrent + - amount.go:Rounded probably does NOT handle float precision well... it is float64 + tho... + - my `go mod tidy` actually cleared `go.mod` file, probably weird localhost backwards + compatilble stuff + ts: Sun Oct 15 11:24:28 MDT 2023 +- todo: go test + subtasks: + - TestAnalyzer_TransctionsSum + - TestAnalyzer_LargestTransaction + - TestAnalyzer_DuplicatesExcluded + - TestAnalyzer_GroupByCategory + - TestAnalyzer_BigSpendersReport + - TestAnalyzer_TransactionsFromURLs + - TestAnalyzer_TransactionsFromURLsConcurrent + - amount.go:Rounded probably does NOT handle float precision well... it is float64 + tho... + - my `go mod tidy` actually cleared `go.mod` file, probably weird localhost backwards + compatilble stuff + ts: Sun Oct 15 11:24:56 MDT 2023