Module: Zitdunyet::Evaluation

Included in:
Completeness
Defined in:
lib/zitdunyet/evaluation.rb

Instance Method Summary collapse

Instance Method Details

#checklistObject



57
58
59
60
# File 'lib/zitdunyet/evaluation.rb', line 57

def checklist
  percent_complete unless @checklist
  @checklist
end

#complete?Boolean

Returns:

  • (Boolean)


4
5
6
7
# File 'lib/zitdunyet/evaluation.rb', line 4

def complete?
  self.class.checklist.each { |item| return false unless item.logic.call(self) }
  true
end

#hintsObject



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/zitdunyet/evaluation.rb', line 44

def hints
  percent_complete unless @hints
  hints = {}
  @hints.each_pair do |hint, pct|
    if hint.respond_to? :call
      hints[hint.call(self)] = pct
    else
      hints[hint.to_s] = pct
    end
  end
  hints
end

#percent_completeObject



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
  # Scale the percentages if they don't add up to 100.  When units are part of the mix, scale the units to fit into
  # the percentage slice leftover after totaling the percentages.
  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