Merge pull request #34 from tom-dudley/custom-workout

Add support for custom workouts
master
Nikola Petkov 7 years ago committed by GitHub
commit 611f6babc9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      README.md
  2. 12
      src/main/scala/com.github.mgifos.workouts/model/Workout.scala

@ -75,7 +75,7 @@ The reserved keywords of the notation are: workout, warmup, cooldown, run, bike,
**`<header>`** := `<sport>: <name>` **`<header>`** := `<sport>: <name>`
**`<sport>`** := (running | cycling) **`<sport>`** := (running | cycling | custom)
**`<name>`** := `[\u0020-\u007F]+` (printable ascii characters) **`<name>`** := `[\u0020-\u007F]+` (printable ascii characters)

@ -13,7 +13,7 @@ case class WorkoutDef(sport: String, name: String, steps: Seq[Step] = Nil) exten
def json: JsValue = Json.obj( def json: JsValue = Json.obj(
"sportType" -> Json.obj( "sportType" -> Json.obj(
"sportTypeId" -> sportId(sport), "sportTypeId" -> sportId(sport),
"sportTypeKey" -> sport), "sportTypeKey" -> sportTypeKey(sport)),
"workoutName" -> name, "workoutName" -> name,
"workoutSegments" -> Json.arr( "workoutSegments" -> Json.arr(
Json.obj( Json.obj(
@ -34,7 +34,7 @@ case class WorkoutNote(note: String) extends Workout {
object Workout { object Workout {
private val WorkoutHeader = """^(running|cycling):\s([\u0020-\u007F]+)(([\r\n]+\s*\-\s[a-z]+:.*)*)$""".r private val WorkoutHeader = """^(running|cycling|custom):\s([\u0020-\u007F]+)(([\r\n]+\s*\-\s[a-z]+:.*)*)$""".r
private val NextStepRx = """^((-\s\w*:\s.*)(([\r\n]+\s{1,}-\s.*)*))(([\s].*)*)$""".r private val NextStepRx = """^((-\s\w*:\s.*)(([\r\n]+\s{1,}-\s.*)*))(([\s].*)*)$""".r
def parseDef(x: String)(implicit msys: MeasurementSystems.MeasurementSystem): Either[String, WorkoutDef] = { def parseDef(x: String)(implicit msys: MeasurementSystems.MeasurementSystem): Either[String, WorkoutDef] = {
@ -59,6 +59,12 @@ object Workout {
def sportId(sport: String) = sport match { def sportId(sport: String) = sport match {
case "running" => 1 case "running" => 1
case "cycling" => 2 case "cycling" => 2
case _ => throw new IllegalArgumentException("Only running and cycling workouts are supported.") case "custom" => 3
case _ => throw new IllegalArgumentException("Only running, cycling and 'custom' workouts are supported.")
}
def sportTypeKey(sport: String) = sport match {
case "custom" => "other"
case _ => sport
} }
} }

Loading…
Cancel
Save