aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/reading/models/Book.scala
blob: 34af272adb47004c6f1d8ee088885c62871f8855 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package reading.models

case class Book(
    title: String,
    author: String,
    year: String,
    parts: Int = 1,
    period: Option[Period],
    genres: Seq[Genre],
    themes: Seq[Theme],
    programs: Seq[Program],
    level: Level
) extends Ordered[Book] {
  def compare(that: Book) = {
    def formatTitle(title: String) =
      title
        .toLowerCase
        .replaceAll("^les ", "")
        .replaceAll("^le ", "")
        .replaceAll("^l’", "")
        .replaceAll("^à la ", "")
        .replaceAll("^au ", "")
        .replaceAll("^aux ", "")
        .replaceAll("é", "e")
        .replaceAll("è", "e")
    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)))
}