fixstmt

Tool to rename bank statements to yyyy-mm-dd format
git clone https://git.bracken.jp/fixstmt.git
Log | Files | Refs | LICENSE

commit 7f4a32404901c07bce2b3a3b308617560097cde0
parent 79bd9e0e30a4d896b2511637425dd0b1f6edce9a
Author: Chris Bracken <chris@bracken.jp>
Date:   Thu,  6 Jan 2022 20:41:11 -0800

Add support for Shinsei statements

Diffstat:
Mconvert/convert.go | 32+++++++++++++++++++++++++++++++-
Mconvert/convert_test.go | 30++++++++++++++++++++++++++++++
2 files changed, 61 insertions(+), 1 deletion(-)

diff --git a/convert/convert.go b/convert/convert.go @@ -13,11 +13,21 @@ type Converter interface { Convert(fname string) (string, error) } +// RbcDirectInvesting is a Converter for RBC Direct Investing statements. type RbcDirectInvesting struct{} + +// AppleCard is a Converter for Apple Card (MasterCard) statements. type AppleCard struct{} +// ShinseiBank is a Converter for Shinsei Bank statements. +type ShinseiBank struct{} + func ConverterForFile(fname string) (Converter, error) { - converters := []Converter{&AppleCard{}, &RbcDirectInvesting{}} + converters := []Converter{ + &AppleCard{}, + &RbcDirectInvesting{}, + &ShinseiBank{}, + } for _, c := range converters { if c.CanConvert(fname) { return c, nil @@ -70,6 +80,26 @@ func (c *AppleCard) Convert(fname string) (string, error) { return newFname, nil } +func (c *ShinseiBank) Type() string { + return "Shinsei Bank" +} + +func (c *ShinseiBank) CanConvert(fname string) bool { + // TODO: this will break in the year 3000. + // Even more terrifying if we're still using PDFs. + r := regexp.MustCompile(`2\d{15}\.pdf`) + return r.MatchString(strings.ToLower(fname)) +} + +// Format: YYYYmmBBBAAAAAAA.pdf where BBB is the branch number and AAAAAAA is +// the 7-digit account number. +func (c *ShinseiBank) Convert(fname string) (string, error) { + y := fname[0:4] + m := fname[4:6] + newFname := fmt.Sprintf("%s-%s.pdf", y, m) + return newFname, nil +} + func getMonthNumber(m string) (string, error) { switch { case m == "jan" || m == "january": diff --git a/convert/convert_test.go b/convert/convert_test.go @@ -13,6 +13,7 @@ func TestConverterForFile(t *testing.T) { }{ {"123456789-2007jAn10-2007FeB09.pdf", "RBC Direct Investing"}, {"Apple Card Statement - JaNUarY 2020.pdf", "Apple Card"}, + {"2021061230123456.pdf", "Shinsei Bank"}, } for _, tc := range testCases { got, err := convert.ConverterForFile(tc.name) @@ -86,3 +87,32 @@ func TestAppleCard(t *testing.T) { } } } + +func TestShinseiBank(t *testing.T) { + testCases := []struct { + name string + want string + }{ + {"2005011230123456", "2005-01.pdf"}, + {"2016021230123456", "2016-02.pdf"}, + {"2027031230123456", "2027-03.pdf"}, + {"2038041230123456", "2038-04.pdf"}, + {"2049051230123456", "2049-05.pdf"}, + {"2050061230123456", "2050-06.pdf"}, + {"2061071230123456", "2061-07.pdf"}, + {"2072081230123456", "2072-08.pdf"}, + {"2083091230123456", "2083-09.pdf"}, + {"2094101230123456", "2094-10.pdf"}, + {"2105111230123456", "2105-11.pdf"}, + {"2116121230123456", "2116-12.pdf"}, + } + converter := convert.ShinseiBank{} + for _, tc := range testCases { + got, err := converter.Convert(tc.name) + if err != nil { + t.Errorf("Failed to convert file %s: %s", tc.name, err) + } else if got != tc.want { + t.Errorf("In(%s) = %s; want %s", tc.name, got, tc.want) + } + } +}