Class: Gaku::Student

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Addresses, Contacts, Notes, Pagination, Person, Picture
Defined in:
app/models/gaku/student.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.activeObject



77
78
79
# File 'app/models/gaku/student.rb', line 77

def self.active
  where(enrollment_status_code: EnrollmentStatus.active.pluck(:code))
end

.specialtiesObject



73
74
75
# File 'app/models/gaku/student.rb', line 73

def self.specialties
  student_specialties.map &:name
end

Instance Method Details

#activeObject



101
102
103
104
105
106
107
108
# File 'app/models/gaku/student.rb', line 101

def active
  enrollment_status = EnrollmentStatus.find_by(code: enrollment_status_code)
  if enrollment_status
    enrollment_status.active?
  else
    false
  end
end

#identification_numberObject



60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/models/gaku/student.rb', line 60

def identification_number
  '%surname-%name-%id'.gsub(/%(\w+)/) do |s|
    case s
    when '%name'
      name.downcase
    when '%surname'
      surname.downcase
    when '%id'
      id
    end
  end
end

#major_specialtyObject



55
56
57
# File 'app/models/gaku/student.rb', line 55

def major_specialty
  student_specialties.ordered.first.specialty if student_specialties.any?
end

#make_enrolledObject



48
49
50
51
52
53
# File 'app/models/gaku/student.rb', line 48

def make_enrolled
  enrollment_status = EnrollmentStatus.where( code: 'enrolled',
                                              active: true, immutable: true).first_or_create!.try(:code)
  update_column(:enrollment_status_code, enrollment_status)
  save
end

#set_foreign_id_codeObject



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'app/models/gaku/student.rb', line 85

def set_foreign_id_code
  if preset = Preset.active
    if preset.increment_foreign_id_code == '1'
      self.foreign_id_code = (preset.last_foreign_id_code.to_i + 1).to_s
      preset.last_foreign_id_code = self.foreign_id_code
      preset.save!
    else
      if self.foreign_id_code.to_i.is_a? Integer
        preset.increment_foreign_id_code = true
        preset.last_foreign_id_code = self.foreign_id_code
        preset.save!
      end
    end
  end
end

#set_scholarship_statusObject



81
82
83
# File 'app/models/gaku/student.rb', line 81

def set_scholarship_status
  self.scholarship_status = ScholarshipStatus.find_by(default: true)
end