RUB symbol was added

master
voidd 5 years ago
parent d8104ef735
commit fa17d92b45
  1. 20
      layout.go
  2. 8
      sorter.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 `-`

@ -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)
}

Loading…
Cancel
Save