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
|
# File 'lib/zitdunyet/evaluation.rb', line 9
def percent_complete
unit_percentage = 0
pct_percentage = 1
if self.class.percentage < 100
unit_percentage = ((100 - self.class.percentage) / self.class.units.to_f) if (self.class.units > 0)
pct_percentage = (100 / self.class.percentage.to_f) if (self.class.units == 0)
elsif self.class.percentage > 100
pct_percentage = (100 / self.class.percentage.to_f) if (self.class.units == 0)
end
completed_pct = 0
completed_units = 0
complete = true
@hints = {}
@checklist = {}
self.class.checklist.each do |item|
completed = item.logic.call(self)
@checklist[item.label] = completed
if completed
if item.percent
completed_pct += item.percent
else
completed_units += item.units if item.units
end
else
complete = false
hint = item.hint || item.label
@hints[hint] = item.percent ? item.percent * pct_percentage : item.units * unit_percentage
end
end
complete ? 100 : (completed_pct * pct_percentage) + (completed_units * unit_percentage)
end
|