Class: Gaku::ExamPortion

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
ActiveModel::Dirty
Defined in:
app/models/gaku/exam_portion.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#custom_errorsObject

Returns the value of attribute custom_errors.



5
6
7
# File 'app/models/gaku/exam_portion.rb', line 5

def custom_errors
  @custom_errors
end

Instance Method Details

#correct_weight_with_errorObject



34
35
36
# File 'app/models/gaku/exam_portion.rb', line 34

def correct_weight_with_error
  self.weight = weight_was
end

#init_weightObject



56
57
58
59
60
61
62
63
# File 'app/models/gaku/exam_portion.rb', line 56

def init_weight
  if weight.nil?
    other_ep = exam.exam_portions
    percentage = 100 / (other_ep.count + 1)
    self.weight = percentage
    other_ep.update_all weight: percentage
  end
end

#student_score(student) ⇒ Object



65
66
67
# File 'app/models/gaku/exam_portion.rb', line 65

def student_score(student)
  exam_portion_scores.where(student_id: student.id).first
end

#to_sObject



30
31
32
# File 'app/models/gaku/exam_portion.rb', line 30

def to_s
  name
end

#weight_calculateObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/models/gaku/exam_portion.rb', line 38

def weight_calculate
  if (exam.total_weight_except(self) + weight) > 100
    last = exam.exam_portions.last

    interval = weight - weight_was
    if self != last
      if interval <= last.weight
        last.update_attribute(:weight, last.weight - interval)
      else
        correct_weight_with_error
      end
    else
      correct_weight_with_error
    end

  end
end