[Pharo] Personal fitness tracker web app.
1
"
2
I represent a log of workouts.
3
"
4
Class {
5
#name : 'MFTWorkoutLogBook',
6
#superclass : 'MFTObject',
7
#instVars : [
8
'workoutLogs'
9
],
10
#category : 'MyFitnessTracker-Core-Logging',
11
#package : 'MyFitnessTracker-Core',
12
#tag : 'Logging'
13
}
14
15
{ #category : 'initialization' }
16
MFTWorkoutLogBook >> canonicalName [
17
18
^ workoutLogs size asString , ' workouts logged'
19
]
20
21
{ #category : 'adding' }
22
MFTWorkoutLogBook >> durationSinceLastWorkout [
23
24
^ workoutLogs
25
ifEmpty: [ nil ]
26
ifNotEmpty: [ DateAndTime now - workoutLogs last finish ]
27
]
28
29
{ #category : 'initialization' }
30
MFTWorkoutLogBook >> initialize [
31
32
super initialize.
33
workoutLogs := OrderedCollection new
34
]
35
36
{ #category : 'adding' }
37
MFTWorkoutLogBook >> lastLogForExercise: aMFTExercise [
38
"Answer the most recent workout log during which this exercise was performed."
39
40
| lastLog |
41
lastLog := (workoutLogs select: [ :workout |
42
workout exercises includes: aMFTExercise ])
43
ifEmpty: [ ^ nil ]
44
ifNotEmpty: [ :logs | logs detectMax: #finish ].
45
^ lastLog
46
]
47
48
{ #category : 'adding' }
49
MFTWorkoutLogBook >> lastLogForPrescription: aMFTWorkoutPrescription [
50
"Answer the most recent workout log for this workout prescription."
51
52
| lastLog |
53
lastLog := (workoutLogs select: [ :log |
54
log prescription = aMFTWorkoutPrescription ])
55
ifEmpty: [ ^ nil ]
56
ifNotEmpty: [ :logs | logs detectMax: #finish ].
57
^ lastLog
58
]
59
60
{ #category : 'adding' }
61
MFTWorkoutLogBook >> logWorkout: aMFTWorkoutLog [
62
63
workoutLogs addLast: aMFTWorkoutLog
64
]
65
66
{ #category : 'removing' }
67
MFTWorkoutLogBook >> removeWorkoutLog: aMFTWorkoutLog [
68
69
workoutLogs remove: aMFTWorkoutLog
70
]
71
72
{ #category : 'as yet unclassified' }
73
MFTWorkoutLogBook >> workoutLogIsInProgress [
74
75
^ workoutLogs
76
ifEmpty: [ false ]
77
ifNotEmpty: [ workoutLogs last finish isNil ]
78
]
79
80
{ #category : 'initialization' }
81
MFTWorkoutLogBook >> workoutLogs [
82
83
^ workoutLogs
84
]
85