Class: FindId
- Inherits:
-
Object
- Object
- FindId
- Defined in:
- app/lib/find_id.rb
Overview
This class handles finding or creating ids for different models.
Class Method Summary (collapse)
-
+ (Number) degree(year, degree_type, institution_name)
Finds a degree's id from the Degree table.
-
+ (Number) institution(name)
Finds an institution's id in the Institutions table.
-
+ (Number) mentor_supervisor(mentor_supervisor_name, institution_name)
Finds a mentor or supervisor's id in the People table.
-
+ (Number) person(name)
Finds a person's id in the People table.
Class Method Details
+ (Number) degree(year, degree_type, institution_name)
Finds a degree's id from the Degree table. Creates a new degree if it doesn't exist.
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/lib/find_id.rb', line 55 def self.degree(year, degree_type, institution_name) degree_type = degree_type.downcase institution_id = self.institution(institution_name) Degree.create_with(approved: false) .find_or_create_by(year: year, degree_type: degree_type, institution_id: institution_id) degree_id = Degree.find_by(:year => year, :degree_type => degree_type, :institution_id => institution_id).id return degree_id end |
+ (Number) institution(name)
Finds an institution's id in the Institutions table. Creates a new institution if it doesn't exist.
40 41 42 43 44 45 46 |
# File 'app/lib/find_id.rb', line 40 def self.institution(name) name = name.downcase Institution.create_with(approved: false).find_or_create_by(name: name) institution_id = Institution.find_by(name: name).id return institution_id end |
+ (Number) mentor_supervisor(mentor_supervisor_name, institution_name)
This only checks for the name. It won't create a new person if only the institution is different
Finds a mentor or supervisor's id in the People table. Creates a new person with the given institution and nil position if it doesn't exist.
24 25 26 27 28 29 30 31 32 33 |
# File 'app/lib/find_id.rb', line 24 def self.mentor_supervisor(mentor_supervisor_name, institution_name) mentor_supervisor_name = mentor_supervisor_name.downcase institution_name = institution_name.downcase institution_id = self.institution(institution_name) Person.create_with(position: nil, institution_id: institution_id, approved: false) .find_or_create_by(name: mentor_supervisor_name) mentor_supervisor_id = Person.find_by(name: mentor_supervisor_name).id return mentor_supervisor_id end |
+ (Number) person(name)
Finds a person's id in the People table. Creates a new person with nil position and institution if it doesn't exist.
9 10 11 12 13 14 15 16 |
# File 'app/lib/find_id.rb', line 9 def self.person(name) name = name.downcase Person.create_with(position: nil, institution_id: nil, approved: false) .find_or_create_by(name: name) person_id = Person.find_by(name: name).id return person_id end |