Class: Information

Inherits:
Object
  • Object
show all
Defined in:
app/lib/information.rb

Overview

This class handles information from submit and edit sent to the backend.

Class Method Summary (collapse)

Class Method Details

+ (Hash{String} => String, Number) submit_handling(name, position, institution_name, postdoc_array, degree_array)

Note:

It assumes that all parameters are filled out by the user.

Handles the information for submitting a new person's details.

Parameters:

  • name (String)

    name of the person

  • position (String)

    current position of the person

  • institution_name (String)

    current institution of the person

  • postdoc_array (Array<Hash{String => String, Number}>)

    array of the person's postdoc information

  • degree_array (Array<Hash{String => String, Number}>)

    array of the person's degree information

Returns:

  • (Hash{String} => String, Number)

    created person in the database



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/lib/information.rb', line 13

def Information.submit_handling(name, position, institution_name, postdoc_array, degree_array)
  person = Person.new_person(name.downcase, position, institution_name)

  # Checks that the postdoc_array is not null before adding new mentorships
  unless postdoc_array.nil?
    postdoc_array.each do |postdoc|
      Mentorship.new_mentorship(name.downcase, postdoc[:pdSupervisor], postdoc[:pdInstitution],
        postdoc[:pdStartYear], postdoc[:pdEndYear])
    end
  end

  # Checks that degree_array is not nil before adding new degrees and supervisions
  unless degree_array.nil?
    degree_array.each do |degree|
      Degree.new_degree(degree[:year], degree[:type], degree[:institution])
      Supervision.new_supervision(degree[:year], degree[:type], degree[:institution], name, degree[:supervisor])
    end
  end

  return person
end

+ (Hash{String => String}) update_handling(id, name, position, institution_name, postdoc_array, degree_array)

Note:

It assumes that all parameters are filled out by the user.

Handles the information for editing a person's details.

Parameters:

  • id (Number)

    id of the person

  • name (String)

    name of the person

  • position (String)

    current position of the person

  • institution_name (String)

    current institution of the person

  • postdoc_array (Array<Hash{String => String, Number}>)

    array of the person's postdoc information

  • degree_array (Array<Hash{String => String, Number}>)

    array of the person's degree information

Returns:

  • (Hash{String => String})

    updated person



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'app/lib/information.rb', line 45

def Information.update_handling(id, name, position, institution_name, postdoc_array, degree_array)

  # Gets the person's information from the People table
  person_object = Person.find(id)

  # Updates if the person's name is not nil
  # Checks if the name is the same. If not, change it.
  unless name.nil?
    if person_object.name != name
      Person.update(id, name: name.downcase)
    end
  end

  # Updates if the person's posiiton is not nil
  # Checks if the position is the same. If not, change it.
  unless position.nil?
    if person_object.position !=  position
      Person.update(id, position: position)
    end
  end

  # Updates if the person's institution is not nil
  # Checks if the institution is the same. If not, change it.
  unless institution_name.nil?
    institution_id = FindId.institution(institution_name)
    if person_object.institution_id != institution_id
      Person.update(id, institution_id: institution_id)
    end
  end

  # Update postdocs and degrees respectively
  Mentorship.update_mentorship(id, name, postdoc_array)
  Supervision.update_supervision(id, name, degree_array)

  # Updates person_object (not sure if we need this)
  person_object = Person.find(id)
  return person_object
end