diff --git a/album.go b/album.go index 753ff56..d000826 100644 --- a/album.go +++ b/album.go @@ -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 +} diff --git a/album_test.go b/album_test.go index eec4519..a7dead7 100644 --- a/album_test.go +++ b/album_test.go @@ -11,3 +11,30 @@ func Test(t *testing.T) { TestingT(t) } type AlbumSuite struct{} 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) + } + } + +}