Class: Gaku::Grading::Single::Percentage

Inherits:
BaseMethod
  • Object
show all
Defined in:
lib/gaku/grading/single/percentage.rb

Instance Attribute Summary collapse

Attributes inherited from BaseMethod

#criteria, #gradable, #gradable_scope, #gradable_type, #result, #student

Instance Method Summary collapse

Methods inherited from BaseMethod

#grade, #initialize

Constructor Details

This class inherits a constructor from Gaku::Grading::Single::BaseMethod

Instance Attribute Details

#scoresObject (readonly)

Returns the value of attribute scores.



3
4
5
# File 'lib/gaku/grading/single/percentage.rb', line 3

def scores
  @scores
end

Instance Method Details

#formated_scoreObject



22
23
24
# File 'lib/gaku/grading/single/percentage.rb', line 22

def formated_score
  score.try(:*, 100).try(:round, 3)
end

#grade_examObject



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/gaku/grading/single/percentage.rb', line 5

def grade_exam
  exam = @gradable

  @scores = []
  @max_score = exam.max_score
  exam.exam_portions.select(&:score?).each_with_index do |exam_portion, index|
    ep_score = @student.exam_portion_scores.find_by(gradable: gradable_scope, exam_portion_id: exam_portion.id)
    @scores << ep_score.score if ep_score.score
  end

  @result = { id: @student.id, score: formated_score }
end

#scoreObject



18
19
20
# File 'lib/gaku/grading/single/percentage.rb', line 18

def score
  @scores.inject(:+) / @max_score unless @scores.blank?
end