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



37
38
39
# File 'app/models/gaku/exam_portion.rb', line 37

def correct_weight_with_error
  self.weight = weight_was
end

#init_weightObject



59
60
61
62
63
64
65
66
# File 'app/models/gaku/exam_portion.rb', line 59

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



68
69
70
# File 'app/models/gaku/exam_portion.rb', line 68

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

#to_sObject



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

def to_s
  name
end

#weight_calculateObject



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

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