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



63
64
65
# File 'app/models/gaku/student.rb', line 63

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

.specialtiesObject



59
60
61
# File 'app/models/gaku/student.rb', line 59

def self.specialties
  student_specialties.map & :name
end

Instance Method Details

#activeObject



97
98
99
100
101
102
103
104
# File 'app/models/gaku/student.rb', line 97

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

#full_nameObject



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

def full_name
  "#{surname} #{name}"
end

#identification_numberObject



80
81
82
83
84
85
86
87
88
89
90
91
# File 'app/models/gaku/student.rb', line 80

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



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

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

#make_enrolledObject



67
68
69
70
71
72
73
74
# File 'app/models/gaku/student.rb', line 67

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_scholarship_statusObject



93
94
95
# File 'app/models/gaku/student.rb', line 93

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

#temp_genderObject



106
107
108
109
110
111
112
113
# File 'app/models/gaku/student.rb', line 106

def temp_gender
  if gender
    I18n.t('gender.male')
  else
    I18n.t('gender.female')
  end

end