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_scope, #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
22 23 24 |
# File 'lib/gaku/grading/single/percentage.rb', line 22 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 |
# 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 |
#score ⇒ Object
18 19 20 |
# File 'lib/gaku/grading/single/percentage.rb', line 18 def score @scores.inject(:+) / @max_score unless @scores.blank? end |