Class: Gaku::Student

Inherits:
ApplicationRecord show all
Includes:
Addresses, Contacts, Notes, Pagination, Person
Defined in:
app/models/gaku/student.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.activeObject



70
71
72
# File 'app/models/gaku/student.rb', line 70

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

.ransackable_attributes(auth_object = nil) ⇒ Object



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

def self.ransackable_attributes(auth_object = nil)
  super & %w(enrollment_status_code)
end

.specialtiesObject



66
67
68
# File 'app/models/gaku/student.rb', line 66

def self.specialties
  student_specialties.map & :name
end

Instance Method Details

#activeObject



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

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

#full_nameObject



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

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

#identification_numberObject



91
92
93
94
95
96
97
98
99
100
101
102
# File 'app/models/gaku/student.rb', line 91

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



87
88
89
# File 'app/models/gaku/student.rb', line 87

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

#make_enrolledObject



78
79
80
81
82
83
84
85
# File 'app/models/gaku/student.rb', line 78

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



104
105
106
# File 'app/models/gaku/student.rb', line 104

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

#temp_genderObject



117
118
119
120
121
122
123
124
# File 'app/models/gaku/student.rb', line 117

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

end