Class: Gaku::Grading::Single::Percentage
- Inherits:
-
BaseMethod
- Object
- BaseMethod
- Gaku::Grading::Single::Percentage
- Defined in:
- lib/gaku/grading/single/percentage.rb
Instance Attribute Summary collapse
-
#scores ⇒ Object
readonly
Returns the value of attribute scores.
Attributes inherited from BaseMethod
#criteria, #gradable, #gradable_type, #result, #student
Instance Method Summary collapse
Methods inherited from BaseMethod
Constructor Details
This class inherits a constructor from Gaku::Grading::Single::BaseMethod
Instance Attribute Details
#scores ⇒ Object (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_score ⇒ Object
23 24 25 |
# File 'lib/gaku/grading/single/percentage.rb', line 23 def formated_score score.try(:*, 100).try(:round, 3) end |
#grade_exam ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/gaku/grading/single/percentage.rb', line 5 def grade_exam exam = @gradable @scores = [] @max_score = exam.max_score exam.exam_portions.each_with_index do |exam_portion, index| ep_score = @student.exam_portion_scores.where(exam_portion_id: exam_portion.id).first_or_create! @scores << ep_score.score if ep_score.score end @result = { id: @student.id, score: formated_score } end |
#score ⇒ Object
19 20 21 |
# File 'lib/gaku/grading/single/percentage.rb', line 19 def score @scores.inject(:+) / @max_score unless @scores.blank? end |