package aboutme
import java.time.{LocalDate, Month, Period}
import imaginary.ConsoleUtils
case class Music(
trackName: String,
artists: List[String],
genre: String,
spotifyLink: String
) {
override def toString: String =
s"• $trackName by ${artists.mkString(", ")} [$genre]"
}
case class Book(
title: String,
author: String,
edition: String,
isbn: String
) {
override def toString: String =
s"• $title by $author ($edition) [ISBN $isbn]"
}
class Person(
val profilePath: String,
val fullname: String,
val title: String,
val location: String,
val birthdate: LocalDate,
val passion: String,
val musics: List[Music],
val books: List[Book]
) {
def introduce(): String = {
ConsoleUtils.displayImage(profilePath, ConsoleUtils.ALIGN_CENTER,
s"${ConsoleUtils.bigger(fullname)}\n${Period.between(birthdate, LocalDate.now()).getYears} years old\n$title\n$location")
}
def recommendMusics(playlist: (String, String)): String = {
val startSentence = "Artists and musics I'd recommend listening:\n"
val playlistSentence = "\n"*2 + "Check out my Spotify playlist:" + ConsoleUtils.hypertextlink(playlist._1, playlist._2)
(for m <- musics yield ConsoleUtils.hypertextlink(m.toString, m.spotifyLink)).mkString(startSentence, "\n", playlistSentence)
}
def recommendBooks(): String = {
s"Here are ${books.length} books I'd recommend:\n" +
books.mkString("\n")
}
}
object AboutMe {
def main(args: Array[String]): Unit = {
val me = new Person(
"profilepic.png",
"Allan Brunner",
"Software Developer",
"Muraz (Collombey), Switzerland",
LocalDate.of(2005, Month.APRIL, 1),
"My passion lies in science and in understanding how the world works.\n" +
"Whether it's atoms, biology, or the vastness of space, I love learning about it all.\n" +
"If it's related to science, it will likely capture my interest.",
List(
Music("Get Wrecked 2024 Tool", List("Dual Damage"),
"HARDSTYLE", "https://open.spotify.com/track/6AObZNK4BuQNWMUVdDqzr3?si=86c38525b67a4ba7"),
Music("Les ogres", List("Solann"),
"NÉOFOLK", "https://open.spotify.com/track/7maKIQM9dXihvpXAJGSPiV?si=a3f16c5dcf5f4d90"),
Music("Experience", List("Ludovico Einaudi"),
"CLASSIC", "https://open.spotify.com/track/1BncfTJAWxrsxyT9culBrj?si=01847213befa4881")
),
List(
Book("Cogito", "Victor Dixen", "Robert Laffon", "978-2-221-24172-1"),
Book("The Name of the Wind", "Patrick Rothfuss", "Gollancz", "978-0-575-08140-6")
)
)
println(me.introduce())
println("\n=== = PASSION = ===")
println(me.passion)
println("\n=== == MUSIC == ===")
println(me.recommendMusics(("Liked Songs", "https://open.spotify.com/playlist/4bW6kZFcICPGOV2s70X55l?si=d8fdaa8be51a4c98")))
println("\n=== == BOOKS == ===")
println(me.recommendBooks())
}
}