Class: StudentInputFormControllerCreate

Inherits:
Object
  • Object
show all
Defined in:
lib/source/controllers/student_input_form_controller.rb,
lib/source/controllers/student_input_form/student_input_form_controller_create.rb

Instance Method Summary collapse

Constructor Details

#initialize(parent_controller) ⇒ StudentInputFormControllerCreate

Returns a new instance of StudentInputFormControllerCreate.



6
7
8
# File 'lib/source/controllers/student_input_form_controller.rb', line 6

def initialize(parent_controller)
  @parent_controller = parent_controller
end

Instance Method Details

#on_view_createdObject



14
15
# File 'lib/source/controllers/student_input_form_controller.rb', line 14

def on_view_created
end

#process_fields(fields) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/source/controllers/student_input_form_controller.rb', line 17

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

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

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

    StudentsListDB.add_student(student)

    @view.close
  rescue ArgumentError => e
    api = Win32API.new('user32', 'MessageBox', ['L', 'P', 'P', 'L'], 'I')
    api.call(0, e.message, 'Error', 0)
  end
end

#refreshObject



16
17
18
# File 'lib/source/controllers/student_input_form/student_input_form_controller_create.rb', line 16

def refresh
  @parent_controller.refresh_data(1, 20)
end

#set_view(view) ⇒ Object



10
11
12
# File 'lib/source/controllers/student_input_form_controller.rb', line 10

def set_view(view)
  @view = view
end