Adds list of author computation

This commit is contained in:
2016-01-25 13:13:57 +01:00
parent 88ab821c58
commit 594598ed6b
2 changed files with 58 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
package main
import (
"regexp"
"strconv"
"time"
)
@@ -70,3 +71,33 @@ type Album struct {
func AlbumIDString(ID AlbumID) string {
return strconv.FormatUint(uint64(ID), 10)
}
var rxAuthorSkip = regexp.MustCompile(`\A<.*>\z`)
func (a *Album) Authors() []string {
authorsUnsafe := make([]string, 0, len(a.Scenarists)+len(a.Colorists)+len(a.Designers))
authors := make([]string, 0, len(a.Scenarists)+len(a.Colorists)+len(a.Designers))
set := map[string]bool{}
authorsUnsafe = append(authorsUnsafe, a.Designers...)
authorsUnsafe = append(authorsUnsafe, a.Scenarists...)
authorsUnsafe = append(authorsUnsafe, a.Colorists...)
for _, author := range authorsUnsafe {
if rxAuthorSkip.MatchString(author) == true || set[author] == true {
continue
}
authors = append(authors, author)
set[author] = true
}
return authors
}
func (a *Album) String() string {
res := strconv.FormatUint(uint64(a.ID), 10) + ": "
if len(a.Collection) > 0 {
res += a.Collection + ": "
}
return res + a.Title
}