Merge pull request #67 from voidd/master

Fixes mop-tracker/mop#63
master
Brandon Lee Camilleri 4 years ago committed by GitHub
commit a50752c1a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      layout.go
  2. 10
      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 `-`

@ -105,7 +105,7 @@ func (list byLastTradeDesc) Less(i, j int) bool {
return list.sortable[j].LastTrade < list.sortable[i].LastTrade
}
func (list byChangeDesc) Less(i, j int) bool {
return c(list.sortable[j].ChangePct) < c(list.sortable[i].ChangePct)
return c(list.sortable[j].Change) < c(list.sortable[i].Change)
}
func (list byChangePctDesc) Less(i, j int) bool {
return c(list.sortable[j].ChangePct) < c(list.sortable[i].ChangePct)
@ -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