diff options
Diffstat (limited to 'src/main/scala/reading/models/Book.scala')
-rw-r--r-- | src/main/scala/reading/models/Book.scala | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/src/main/scala/reading/models/Book.scala b/src/main/scala/reading/models/Book.scala index 1e4b81a..b856b7d 100644 --- a/src/main/scala/reading/models/Book.scala +++ b/src/main/scala/reading/models/Book.scala @@ -1,21 +1,20 @@ package reading.models -case class Book( +case class Book ( title: String, author: String, genres: Seq[Genre], themes: Seq[Theme] -) +) extends Ordered[Book] { + def compare(that: Book) = { + def formatTitle(title: String) = + title.toLowerCase.replaceAll("^les ", "").replaceAll("^le ", "") -object Book { - def all: Seq[Book] = Seq( - Book("Les dix petits nègres", "Agatha Christie", Seq(Genre.Detective), Seq(Theme.Fear)), - Book("Le joueur", "Fiódor Dostoyevski", Seq(Genre.Adventure), Seq(Theme.Fear)), - Book("Voyage au bout de la nuit", "Céline", Seq(Genre.Adventure), Seq(Theme.Fear)), - Book("Le petit prince", "Antoine de Saint Exupéry", Seq(Genre.Adventure), Seq(Theme.Friendship)), - Book("Les frères Karamazov", "Fiódor Dostoyevski", Seq(Genre.Adventure), Seq(Theme.Family)) - ) + formatTitle(this.title).compare(formatTitle(that.title)) + } +} +object Book { def filter(books: Seq[Book], filters: Seq[Filter]): Seq[Book] = books.filter(b => filters.forall(_.filter(b))) } |