Class: Menu::PersonOption
Overview
menu class to process the add option for persons
Instance Attribute Summary
Attributes inherited from Base
#menu_description, #menu_items
Instance Method Summary collapse
-
#add_person ⇒ Object
public entry point to print the menu and execute to chosen option.
-
#add_simple_person ⇒ Object
private
method to create and add a simple person.
-
#add_student ⇒ Object
private
method to create and add a student.
-
#define_menu_items ⇒ Object
private
method to define all printable menu items.
-
#determine_action(input) ⇒ Boolean
private
method to process the provided input.
-
#initialize ⇒ PersonOption
constructor
initialization.
Methods inherited from Base
#add_menu_item, #get_entry, #handle_wrong_option, #print_menu
Constructor Details
#initialize ⇒ PersonOption
initialization
7 8 9 10 |
# File 'lib/menu/person_option.rb', line 7 def initialize super @menu_description = "Adds a new Person. Select Type: " end |
Instance Method Details
#add_person ⇒ Object
public entry point to print the menu and execute to chosen option
13 14 15 |
# File 'lib/menu/person_option.rb', line 13 def add_person end |
#add_simple_person ⇒ Object (private)
method to create and add a simple person
42 43 44 45 46 47 48 |
# File 'lib/menu/person_option.rb', line 42 def add_simple_person name = get_entry("Enter name: ") p = Person::Person.new(name) Menu.data_handler.add_person(p) puts "Person with id #{p.id} added successfully.".green end |
#add_student ⇒ Object (private)
method to create and add a student
51 52 53 54 55 56 57 58 |
# File 'lib/menu/person_option.rb', line 51 def add_student name = get_entry("Enter name: ") mat_nr = get_entry("Enter matriculation number: ").to_i s = Person::Student.new(name, mat_nr) Menu.data_handler.add_person(s) puts "Student with id #{s.id} added successfully.".green end |
#define_menu_items ⇒ Object (private)
method to define all printable menu items
20 21 22 23 24 |
# File 'lib/menu/person_option.rb', line 20 def ("Person.", 1) ("Student.", 2) ("Cancel and return to previous menu.", 3) end |
#determine_action(input) ⇒ Boolean (private)
method to process the provided input
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/menu/person_option.rb', line 30 def determine_action(input) case (input.to_i) when 1 then add_simple_person when 2 then add_student when 3 then return false else handle_wrong_option end return true end |