From 816f9cd87349002dc6349af3689397737cc03880 Mon Sep 17 00:00:00 2001 From: Shane Huston Date: Wed, 13 Oct 2021 17:10:17 +0100 Subject: [PATCH] Update report to receive flag for source type Report previously tried to determine the type of input data from the data itself. However, before the report is generated, we already know the source type from the command line arguments. Report now gets passed a flag to specify the type of source data --- transactions/process.go | 4 ++-- transactions/report.go | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/transactions/process.go b/transactions/process.go index 34c913b..b9a8f7d 100644 --- a/transactions/process.go +++ b/transactions/process.go @@ -13,8 +13,8 @@ func Process(revolutFile string, aibFile string, startDate time.Time) { revolutLines := utils.ReadInputFile(revolutFile) aibLines := utils.ReadInputFile(aibFile) - report = report.AddTransactions(revolutLines) - report = report.AddTransactions(aibLines) + report = report.AddTransactions(revolutLines, true) + report = report.AddTransactions(aibLines, false) report.Sort() report.Output() diff --git a/transactions/report.go b/transactions/report.go index e972785..7a9205f 100644 --- a/transactions/report.go +++ b/transactions/report.go @@ -3,7 +3,6 @@ package transactions import ( "fmt" "time" - "strings" "sort" ) @@ -20,8 +19,7 @@ func NewReport(startDate time.Time) *report { return r } -func (r report) AddTransactions(rawData[]string) *report { - isRevolut := strings.HasPrefix(rawData[0], "Completed Date") +func (r report) AddTransactions(rawData[]string, isRevolut bool) *report { if isRevolut { for i := len(rawData) - 1; i > 0; i-- { transaction := NewRevolutTransaction(rawData[i])