\r supported for line break in workout definition #24

master
mgifos 7 years ago
parent 76525db162
commit 1dbbd9043b
  1. 6
      README.md
  2. 2
      src/main/scala/com.github.mgifos.workouts/model/Step.scala
  3. 4
      src/main/scala/com.github.mgifos.workouts/model/Workout.scala
  4. 2
      src/test/scala/com/github/mgifos/workouts/model/WorkoutSpec.scala

@ -93,12 +93,14 @@ The reserved keywords of the notation are: workout, warmup, cooldown, run, bike,
**`<time-duration>`** := `<minutes>:<seconds>` **`<time-duration>`** := `<minutes>:<seconds>`
**`<target>`** := `<zone-target> | <pace-target>` **`<target>`** := `<zone-target> | <pace-target> | <hr-target>`
**`<zone-target>`** := `z[1-6]` **`<zone-target>`** := `z[1-6]`
**`<pace-target>`** := `<pace> - <pace> (mpk | mpm)?` **`<pace-target>`** := `<pace> - <pace> (mpk | mpm)?`
**`<hr-target>`** := `\d{1,3} - \d{1,3} bpm`
**`<speed-target>`** := `<kph-speed> - <kph-speed> (kph | mph)?` **`<speed-target>`** := `<kph-speed> - <kph-speed> (kph | mph)?`
**`<pace>`** := `<minutes>:<seconds>` **`<pace>`** := `<minutes>:<seconds>`
@ -109,6 +111,8 @@ The reserved keywords of the notation are: workout, warmup, cooldown, run, bike,
**`<seconds>`** := `\d{2}` **`<seconds>`** := `\d{2}`
**`<newline>`** := `[\r\n]`
## Unit of measurements (metric vs imperial) ## Unit of measurements (metric vs imperial)
As Garmin supports metric and imperial measurement systems, quick-plan can do this as well. There are two ways of usage: As Garmin supports metric and imperial measurement systems, quick-plan can do this as well. There are two ways of usage:

@ -52,7 +52,7 @@ case class RepeatStep(count: Int, steps: Seq[Step]) extends Step {
object Step { object Step {
private val StepRx = """^(-\s\w*:\s.*)((\n\s{1,}-\s.*)*)$""".r private val StepRx = """^(-\s\w*:\s.*)(([\r\n]+\s{1,}-\s.*)*)$""".r
private val StepHeader = """^\s*-\s*(\w*):(.*)$""".r private val StepHeader = """^\s*-\s*(\w*):(.*)$""".r
private val ParamsRx = """^([\w-\.:\s]+)\s*(@(.*))?$""".r private val ParamsRx = """^([\w-\.:\s]+)\s*(@(.*))?$""".r

@ -34,8 +34,8 @@ case class WorkoutNote(note: String) extends Workout {
object Workout { object Workout {
private val WorkoutHeader = """^(running|cycling):\s([\u0020-\u007F]+)((\n\s*\-\s[a-z]+:.*)*)$""".r private val WorkoutHeader = """^(running|cycling):\s([\u0020-\u007F]+)(([\r\n]+\s*\-\s[a-z]+:.*)*)$""".r
private val NextStepRx = """^((-\s\w*:\s.*)((\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] = {
def loop(w: WorkoutDef, steps: String): Either[String, WorkoutDef] = steps match { def loop(w: WorkoutDef, steps: String): Either[String, WorkoutDef] = steps match {

@ -53,7 +53,7 @@ class WorkoutSpec extends FlatSpec with Matchers {
} }
"Workout" should "support cycling ws" in { "Workout" should "support cycling ws" in {
val testBike = "cycling: cycle-test\n- warmup: 5:00\n- bike: 20km @ 20.0-100kph\n- cooldown: lap-button" val testBike = "cycling: cycle-test\r\n- warmup: 5:00\n- bike: 20km @ 20.0-100kph\r- cooldown: lap-button"
Workout.parseDef(testBike) should be( Workout.parseDef(testBike) should be(
Right( Right(
WorkoutDef("cycling", "cycle-test", Seq( WorkoutDef("cycling", "cycle-test", Seq(

Loading…
Cancel
Save