class Gaku::Grading::Single::Calculations

Attributes

collection_students[R]
exam[R]
gradable_scope[R]
grading_methods[R]
student[R]

Public Class Methods

new(grading_methods, student, exam, gradable_scope, collection_students = nil) click to toggle source
# File lib/gaku/grading/single/calculations.rb, line 8
def initialize(grading_methods, student, exam, gradable_scope, collection_students = nil)
  @exam                = exam
  @student             = student
  @grading_methods     = grading_methods
  @collection_students = collection_students
  @gradable_scope      = gradable_scope
end

Public Instance Methods

calculate() click to toggle source
# File lib/gaku/grading/single/calculations.rb, line 16
def calculate
  {}.tap do |hash|
    @grading_methods.each do |grading_method|
      if grading_method.interval?
        grading = Gaku::Grading::Collection::Interval.new(@exam, collection_students, gradable_scope, grading_method.criteria )
        hash[grading_method.id] = grading.grade
      else
        grading = grading_types[grading_method.grading_type].constantize.new(@exam, @student, gradable_scope, grading_method.criteria)
        hash[grading_method.id] = grading.grade
      end
    end
  end

end

Private Instance Methods

grading_types() click to toggle source
# File lib/gaku/grading/single/calculations.rb, line 33
def grading_types
  ActiveSupport::HashWithIndifferentAccess.new(
    score: 'Gaku::Grading::Single::Score',
    percentage: 'Gaku::Grading::Single::Percentage',
    ordinal: 'Gaku::Grading::Single::Ordinal'
  )
end