Class: FindDetail
- Inherits:
-
Object
- Object
- FindDetail
- Defined in:
- app/lib/find_detail.rb
Overview
*** NOT USING THIS METHOD ***
Class Method Summary (collapse)
-
+ (Object) person(name)
finds and returns the details of a person returns nil if the person does not exist in the database returns an array in the format of [person, [postdocs], [degrees]] if the person does not have any postdocs or degrees, this returns nil.
Class Method Details
+ (Object) person(name)
finds and returns the details of a person returns nil if the person does not exist in the database returns an array in the format of [person, [postdocs], [degrees]] if the person does not have any postdocs or degrees, this returns nil
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/lib/find_detail.rb', line 8 def self.person(name) if Person.exists?(name: name) name = name.downcase # find the person in the database and extracts details from it # currently not using position and institution_id for anything # will remove those lines if we really don't need to extract them person_id = FindId.person(name) person_object = Person.find(person_id) position = person_object.position unless person_object.institution_id.nil? institution_object = Institution.find(person_object.institution_id) institution_name = institution_object.name end # make an array of postdocs that are connected to the person in json # need to check what happens when empty array postdoc_array = Array.new postdoc_list = Mentorship.where(:person_id => person_id) postdoc_list.each do |postdoc_single| # wouldn't this line just grab person id instead of person name? postdoc_array.push(postdoc_single.as_json) end # make arrays of degrees and supervisions that are connected to the person degree_id_array = Array.new degree_array = Array.new supervision_array = Array.new # this returns an array of supervisions with the same person_id supervision_find = Supervision.where(:person_id => person_id) # extracts an array of degree_ids that connect to the person_id # adds each supervision to supervision_array in json format supervision_find.each do |supervision_single| unless degree_id_array.include? supervision_single.degree_id degree_id_array.push(supervision_single.degree_id) supervision_array.push(supervision_single.as_json) end end # extracts an array of degrees from all ids found in the degree_id_array # in json format degree_id_array.each do |degree_single_id| degree = Degree.find(degree_single_id) degree_array.push(degree.as_json) end return {person: person_object.as_json, institution: institution_name, postdoc: postdoc_array, degree: degree_array, # we need to send the title # degree supervision should be packed with degree degree_supervision: supervision_array} end end |