Class: Gaku::Grading::Single::Calculations

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(grading_methods, student, exam, gradable_scope, collection_students = nil) ⇒ Calculations

Returns a new instance of Calculations.



8
9
10
11
12
13
14
# 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

Instance Attribute Details

#collection_studentsObject (readonly)

Returns the value of attribute collection_students.



6
7
8
# File 'lib/gaku/grading/single/calculations.rb', line 6

def collection_students
  @collection_students
end

#examObject (readonly)

Returns the value of attribute exam.



6
7
8
# File 'lib/gaku/grading/single/calculations.rb', line 6

def exam
  @exam
end

#gradable_scopeObject (readonly)

Returns the value of attribute gradable_scope.



6
7
8
# File 'lib/gaku/grading/single/calculations.rb', line 6

def gradable_scope
  @gradable_scope
end

#grading_methodsObject (readonly)

Returns the value of attribute grading_methods.



6
7
8
# File 'lib/gaku/grading/single/calculations.rb', line 6

def grading_methods
  @grading_methods
end

#studentObject (readonly)

Returns the value of attribute student.



6
7
8
# File 'lib/gaku/grading/single/calculations.rb', line 6

def student
  @student
end

Instance Method Details

#calculateObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# 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