Class: Gaku::Student
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Gaku::Student
- Defined in:
- app/models/gaku/student.rb
Class Method Summary collapse
Instance Method Summary collapse
- #active ⇒ Object
- #full_name ⇒ Object
- #identification_number ⇒ Object
- #major_specialty ⇒ Object
- #make_enrolled ⇒ Object
- #set_scholarship_status ⇒ Object
- #temp_gender ⇒ Object
Class Method Details
.active ⇒ Object
63 64 65 |
# File 'app/models/gaku/student.rb', line 63 def self.active where(enrollment_status_code: EnrollmentStatus.active.pluck(:code)) end |
.specialties ⇒ Object
59 60 61 |
# File 'app/models/gaku/student.rb', line 59 def self.specialties student_specialties.map & :name end |
Instance Method Details
#active ⇒ Object
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_name ⇒ Object
55 56 57 |
# File 'app/models/gaku/student.rb', line 55 def full_name "#{surname} #{name}" end |
#identification_number ⇒ Object
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_specialty ⇒ Object
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_enrolled ⇒ Object
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_status ⇒ Object
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_gender ⇒ Object
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 |