Skip to content
This repository has been archived by the owner on Jun 27, 2020. It is now read-only.

Commit

Permalink
Add HasBook, HasSeries, and HasAuthor
Browse files Browse the repository at this point in the history
  • Loading branch information
pgaskin committed Sep 2, 2017
1 parent e798b11 commit e738775
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions book.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,38 @@ func (l *SeriesList) Filtered(filterer func(a Series) bool) *SeriesList {
return &filtered
}

// NameIDList is a list of nameids
type NameIDList []NameID
// HasBook checks whether a book with an id exists
func (l *BookList) HasBook(id string) bool {
exists := false
for _, b := range *l {
if b.ID == id {
exists = true
}
}
return exists
}

// HasAuthor checks whether an author with an id exists
func (l *BookList) HasAuthor(id string) bool {
exists := false
for _, b := range *l {
if b.Author.ID == id {
exists = true
}
}
return exists
}

// HasSeries checks whether a series with an id exists
func (l *BookList) HasSeries(id string) bool {
exists := false
for _, b := range *l {
if b.Series.ID == id {
exists = true
}
}
return exists
}

// NewBookListFromDir creates a BookList from the books in a dir. It will still return a nil error if there are errors indexing some of the books. It will only return an error if there is a problem getting the file list.
func NewBookListFromDir(path, coverdir string, verbose bool) (*BookList, error) {
Expand Down

0 comments on commit e738775

Please sign in to comment.