Card.scala 614 B

123456789101112131415161718192021222324252627282930
  1. package models
  2. import play.api.libs.json._
  3. object Card {
  4. implicit val writes = new Writes[Card] {
  5. def writes(o: Card) = Json.obj(
  6. "word" -> o.word,
  7. "taboo" -> o.taboo
  8. )
  9. }
  10. }
  11. case class Card(word: String, taboo: Set[String]) {
  12. def isTaboo(text: String) = {
  13. val lower = text.toLowerCase
  14. def contains(word: String) = {
  15. lower.indexOf(word.toLowerCase) >= 0
  16. }
  17. // check if text contains word or anything in taboo
  18. (taboo + word).map(contains).foldLeft(false)(_ || _)
  19. }
  20. def isCorrect(text: String) = {
  21. text.toLowerCase.indexOf(word.toLowerCase) >= 0
  22. }
  23. }