Method: StudentInputFormController#process_fields

Defined in:
lib/source/student_input_form_controller.rb

#process_fields(fields) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/source/student_input_form_controller.rb', line 28

def process_fields(fields)
  begin
    last_name = fields.delete(:last_name)
    first_name = fields.delete(:first_name)
    parental_name = fields.delete(:parental_name)

    return if last_name.nil? || first_name.nil? || parental_name.nil?

    student = Student.new(last_name, first_name, parental_name, **fields)

    @student_list.add_student(student)
    LoggerHolder.instance.debug('StudentInputFormController: adding student to DB')
    @view.close
  rescue ArgumentError => e
    api = Win32API.new('user32', 'MessageBox', ['L', 'P', 'P', 'L'], 'I')
    LoggerHolder.instance.debug("StudentInputFormController: wrong fields: #{e.message}")
    api.call(0, e.message, 'Error', 0)
  end
end