@stefanfortuin/workout-creator
Version:
A workout creator for mrc or erg file formats
1 lines • 737 B
JavaScript
class Workout{constructor(){this.description="",this.name="",this.intervals=[]}get duration(){return this.intervals.reduce((a,b)=>+a+ +b.duration,0)}add(a){Array.isArray(a)?a.forEach(a=>this.intervals.push(a)):this.intervals.push(a),this.update()}delete(a){this.intervals=this.intervals.filter(b=>b!=a),this.update()}update(){this.intervals.forEach((a,b)=>{const c=this.intervals[b-1];a.start=c&&0!=b?c.end:0})}save(a){let b="[COURSE HEADER]\nUNITS=ENGLISH\nVERSION=2\n";return b+=`DESCRIPTION=${this.description}\n`,b+=`FILE NAME=${this.name}\n`,b+=`MINUTES ${"mrc"==a?"PERCENT":"WATTS"}\n`,b+="[END COURSE HEADER]\n",b+="[COURSE DATA]\n",b+=this.intervals.map(a=>a.toString()).join(""),b+="[END COURSE DATA]",b}}export default Workout;