From fa17d92b454981aca8e1dcf1aa1b748798070eff Mon Sep 17 00:00:00 2001 From: voidd Date: Sun, 17 May 2020 19:54:31 +0300 Subject: [PATCH] RUB symbol was added --- layout.go | 20 ++++++++++---------- sorter.go | 8 +++++++- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/layout.go b/layout.go index 5b685b8..63f6204 100644 --- a/layout.go +++ b/layout.go @@ -14,6 +14,13 @@ import ( "time" ) +var currencies = map[string]string{ + "RUB": "₽", + "GDB": "£", + "EUR": "€", + "JPY": "¥", +} + // Column describes formatting rules for individual column within the list // of stock quotes. type Column struct { @@ -300,16 +307,9 @@ func currency(str ...string) string { } //default to $ symbol := "$" - switch str[1] { - case "JPY": - symbol = "¥" - break - case "EUR": - symbol = "€" - break - case "GBP": - symbol = "£" - break + c, ok := currencies[str[1]] + if ok { + symbol = c } if str[0] == `N/A` || len(str[0]) == 0 { return `-` diff --git a/sorter.go b/sorter.go index 78d47be..d60996e 100644 --- a/sorter.go +++ b/sorter.go @@ -200,7 +200,13 @@ func (sorter *Sorter) SortByCurrentColumn(stocks []Stock) *Sorter { // The same exact method is used to sort by $Change and Change%. In both cases // we sort by the value of Change% so that multiple $0.00s get sorted proferly. func c(str string) float32 { - trimmed := strings.Replace(strings.Trim(str, ` %`), `$`, ``, 1) + c := "$" + for _, v := range currencies { + if strings.Contains(str,v) { + c = v + } + } + trimmed := strings.Replace(strings.Trim(str, ` %`), c, ``, 1) value, _ := strconv.ParseFloat(trimmed, 32) return float32(value) }