Adds list of author computation
This commit is contained in:
31
album.go
31
album.go
@@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@@ -70,3 +71,33 @@ type Album struct {
|
|||||||
func AlbumIDString(ID AlbumID) string {
|
func AlbumIDString(ID AlbumID) string {
|
||||||
return strconv.FormatUint(uint64(ID), 10)
|
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
|
||||||
|
}
|
||||||
|
|||||||
@@ -11,3 +11,30 @@ func Test(t *testing.T) { TestingT(t) }
|
|||||||
type AlbumSuite struct{}
|
type AlbumSuite struct{}
|
||||||
|
|
||||||
var _ = Suite(&AlbumSuite{})
|
var _ = Suite(&AlbumSuite{})
|
||||||
|
|
||||||
|
func (s *AlbumSuite) TestAuthors(c *C) {
|
||||||
|
data := map[AlbumID][]string{
|
||||||
|
8179: []string{"Berthet, Philippe", "Andreas"},
|
||||||
|
44989: []string{"Loro"},
|
||||||
|
58595: []string{"Plantu"},
|
||||||
|
19762: []string{"Swal, Christophe", "Polouchine, Igor", "Rastoin, Bernard", "Robert, Jacky"},
|
||||||
|
9935: []string{"Fournier, Jean-Claude", "D'Authenay, Anne-Marie"},
|
||||||
|
164: []string{"Adamov, Philippe", "Cothias, Patrick"},
|
||||||
|
22737: []string{"Leo", "Rodolphe", "Scarlett"},
|
||||||
|
32043: []string{"Joan", "Harty", "Ptiluc"},
|
||||||
|
46005: []string{"Tibet"},
|
||||||
|
15875: []string{"Veyron, Martin"},
|
||||||
|
84448: []string{"Delitte, Jean-Yves"},
|
||||||
|
160366: []string{"Trondheim, Lewis", "Findakly, Brigitte"},
|
||||||
|
754: []string{"Bruyninx, Marc"},
|
||||||
|
52100: []string{"Guénet, Nicolas", "Téhy", "Vee, J.M."},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, a := range albumsDataTest {
|
||||||
|
expected, ok := data[a.ID]
|
||||||
|
if c.Check(ok, Equals, true) == true {
|
||||||
|
c.Check(a.Authors(), DeepEquals, expected)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user