-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.rb
57 lines (51 loc) · 2.06 KB
/
helpers.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
def find(table, id)
if id.is_a? Array
id = id[0]
end
data[table].find { |i| i.id == id }
end
def find_all(table, id)
if id.is_a? Array
data[table].select { |i| id.include?(i.id) }
else
data[table].select { |i| i.id == id }
end
end
def practice_session_completed_increments(practice_session)
completed_increments = []
find_all(:exercises_practice_sessions, practice_session.exercises_practice_sessions).each do |eps|
completed_increments.concat(exercise_practice_session_completed_increments(eps))
end
return completed_increments
end
def exercise_practice_session_completed_increments(exercise_practice_session)
completed_increments = []
practice_session = find(:practice_sessions, exercise_practice_session.practice_session)
keyboard_acronym = find(:keyboards, practice_session.keyboard).acronym
# eps.tk_completed and .lik_completed are either nil or an array
if keyboard_acronym == "TK" && exercise_practice_session.tk_completed
exercise_increments = find_all(:exercise_increments, exercise_practice_session.tk_completed)
exercise_increments.select! { |ei| !ei.deprecated }
completed_increments.concat(exercise_increments)
elsif keyboard_acronym == "LIK" && exercise_practice_session.lik_completed
exercise_increments = find_all(:exercise_increments, exercise_practice_session.lik_completed)
exercise_increments.select! { |ei| !ei.deprecated }
completed_increments.concat(exercise_increments)
end
return completed_increments
end
def any_completed_increments?(exercise_set)
exercises = find_all(:exercises, exercise_set.exercises)
exercise_increments = exercises.map { |exercise| find_all(:exercise_increments, exercise.exercise_increments) }.flatten
return exercise_increments.any? { |ei| !ei.deprecated && (ei.tk_completion || ei.lik_completion) }
end
def format_as_time(minutes)
"#{minutes / 60}:#{sprintf('%02d', minutes % 60)}:00"
end
def format_completed_increment_count(count)
if (count > 1)
return "#{count} increments completed"
elsif (count == 1)
return "#{count} increment completed"
end
end