diff options
author | Thomas Voss <mail@thomasvoss.com> | 2024-08-09 18:20:40 +0200 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2024-08-09 18:20:40 +0200 |
commit | 64d251945736fa1ca859bdb0577bafb30625c344 (patch) | |
tree | 7329a4ef1cf0e3d5af15443b5f3f5dde1d1f58ee /mintages | |
parent | ba0d19f4e82a90783c4c7ae052cfd1b45e106aac (diff) |
Just use Parse() instead of ForCountry()
Diffstat (limited to 'mintages')
-rw-r--r-- | mintages/parser.go | 19 | ||||
-rw-r--r-- | mintages/parser_test.go | 20 |
2 files changed, 13 insertions, 26 deletions
diff --git a/mintages/parser.go b/mintages/parser.go index f93fdf4..e352b20 100644 --- a/mintages/parser.go +++ b/mintages/parser.go @@ -4,8 +4,6 @@ import ( "bufio" "fmt" "io" - "os" - "path/filepath" "strconv" "strings" "unicode" @@ -32,18 +30,7 @@ type Data struct { Circ, BU, Proof []Row } -func ForCountry(code string) (Data, error) { - path := filepath.Join("data", "mintages", code) - - f, err := os.Open(path) - if err != nil { - return Data{}, err - } - defer f.Close() - return parse(f, path) -} - -func parse(reader io.Reader, file string) (Data, error) { +func Parse(reader io.Reader, file string) (Data, error) { var ( data Data // Our data struct slice *[]Row // Where to append mintages @@ -150,10 +137,10 @@ func parse(reader io.Reader, file string) (Data, error) { var row Row switch { case mintmark.s == "": - year += 1 + year++ row.Label = strconv.Itoa(year) case mintmark.star: - year += 1 + year++ fallthrough default: row.Label = fmt.Sprintf("%d %s", year, mintmark.s) diff --git a/mintages/parser_test.go b/mintages/parser_test.go index 5d70722..f61b63d 100644 --- a/mintages/parser_test.go +++ b/mintages/parser_test.go @@ -7,7 +7,7 @@ import ( ) func TestParserComplete(t *testing.T) { - data, err := parse(bytes.NewBuffer([]byte(` + data, err := Parse(bytes.NewBuffer([]byte(` BEGIN 2020 BEGIN CIRC 1.000 1001 1002 1003 1004 1005 1006 1007 @@ -82,7 +82,7 @@ func TestParserComplete(t *testing.T) { } func TestParserNoProof(t *testing.T) { - data, err := parse(bytes.NewBuffer([]byte(` + data, err := Parse(bytes.NewBuffer([]byte(` BEGIN 2020 BEGIN CIRC 1.000 1001 1002 1003 1004 1005 1006 1007 @@ -102,7 +102,7 @@ func TestParserNoProof(t *testing.T) { } func TestParserMintmarks(t *testing.T) { - data, err := parse(bytes.NewBuffer([]byte(` + data, err := Parse(bytes.NewBuffer([]byte(` BEGIN 2020 BEGIN CIRC 1.000 1001 1002 1003 1004 1005 1006 1007 @@ -140,7 +140,7 @@ func TestParserMintmarks(t *testing.T) { } func TestParserNoYear(t *testing.T) { - _, err := parse(bytes.NewBuffer([]byte(` + _, err := Parse(bytes.NewBuffer([]byte(` BEGIN CIRC 1.000 1001 1002 1003 1004 1005 1006 1007 2000 ? 2002 2003 2004 2005 2006 2007 @@ -159,7 +159,7 @@ func TestParserNoYear(t *testing.T) { } func TestParserNoType(t *testing.T) { - _, err := parse(bytes.NewBuffer([]byte(` + _, err := Parse(bytes.NewBuffer([]byte(` BEGIN 2020 1.000 1001 1002 1003 1004 1005 1006 1007 2000 ? 2002 2003 2004 2005 2006 2007 @@ -178,7 +178,7 @@ func TestParserNoType(t *testing.T) { } func TestParserNoYearOrType(t *testing.T) { - _, err := parse(bytes.NewBuffer([]byte(` + _, err := Parse(bytes.NewBuffer([]byte(` 1.000 1001 1002 1003 1004 1005 1006 1007 2000 ? 2002 2003 2004 2005 2006 2007 BEGIN BU @@ -196,7 +196,7 @@ func TestParserNoYearOrType(t *testing.T) { } func TestParserBadToken(t *testing.T) { - _, err := parse(bytes.NewBuffer([]byte(` + _, err := Parse(bytes.NewBuffer([]byte(` BEGIN 2020 BEGIN CIRC 1.000 1001 1002 1003 1004 1005 1006 1007 @@ -217,7 +217,7 @@ func TestParserBadToken(t *testing.T) { } func TestParserShortRow(t *testing.T) { - _, err := parse(bytes.NewBuffer([]byte(` + _, err := Parse(bytes.NewBuffer([]byte(` BEGIN 2020 BEGIN CIRC 1.000 1001 1002 1003 1004 1005 1006 1007 @@ -237,7 +237,7 @@ func TestParserShortRow(t *testing.T) { } func TestParserLongRow(t *testing.T) { - _, err := parse(bytes.NewBuffer([]byte(` + _, err := Parse(bytes.NewBuffer([]byte(` BEGIN 2020 BEGIN CIRC 1.000 1001 1002 1003 1004 1005 1006 1007 @@ -257,7 +257,7 @@ func TestParserLongRow(t *testing.T) { } func TestParserBadCoinType(t *testing.T) { - _, err := parse(bytes.NewBuffer([]byte(` + _, err := Parse(bytes.NewBuffer([]byte(` BEGIN 2020 BEGIN CIRCULATED 1.000 1001 1002 1003 1004 1005 1006 1007 |