Sort on card numbers is now numeric. fixes #8
This commit is contained in:
parent
a11c17fbf5
commit
b5139e8af4
@ -2,6 +2,7 @@ package serra
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
@ -111,6 +112,14 @@ func Cards(rarity, set, sortby, name, oracle, cardType string) []Card {
|
||||
|
||||
cards, _ := coll.storage_find(filter, sortStage)
|
||||
|
||||
// This is needed because collectornumbers are strings (ie. "23a") but still we
|
||||
// want it to be sorted numerically ... 1,2,3,10,11,100.
|
||||
if sortby == "number" {
|
||||
sort.Slice(cards, func(i, j int) bool {
|
||||
return filterForDigits(cards[i].CollectorNumber) < filterForDigits(cards[j].CollectorNumber)
|
||||
})
|
||||
}
|
||||
|
||||
return cards
|
||||
}
|
||||
|
||||
|
||||
@ -3,7 +3,9 @@ package serra
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
"unicode"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
@ -167,3 +169,14 @@ func print_price_history(prices []PriceEntry, prefix string) {
|
||||
before = value
|
||||
}
|
||||
}
|
||||
|
||||
func filterForDigits(str string) int {
|
||||
var numStr string
|
||||
for _, c := range str {
|
||||
if unicode.IsDigit(c) {
|
||||
numStr += string(c)
|
||||
}
|
||||
}
|
||||
s, _ := strconv.Atoi(numStr)
|
||||
return s
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user