Class: Menu::EntityAddition
Overview
Instance Attribute Summary
Attributes inherited from Base
#menu_description, #menu_items
Instance Method Summary collapse
-
#add_person ⇒ Object
private
method to start the addition of a person by the PersonOption.
-
#add_task ⇒ Object
private
method to add a new Task defined by the users console input.
-
#create_task_from_input ⇒ Task
private
method to create a task from the provided input.
-
#define_menu_items ⇒ Object
private
method to define all printable menu items.
-
#determine_action(input) ⇒ Boolean
private
method to process the provided input.
-
#initialize ⇒ EntityAddition
constructor
initialization.
Methods inherited from Base
#add_menu_item, #get_entry, #handle_wrong_option, #print_menu
Constructor Details
#initialize ⇒ EntityAddition
initialization
7 8 9 10 |
# File 'lib/menu/entity_addition.rb', line 7 def initialize super @menu_description = "Person and Task Addition" end |
Instance Method Details
#add_person ⇒ Object (private)
method to start the addition of a person by the PersonOption
42 43 44 45 |
# File 'lib/menu/entity_addition.rb', line 42 def add_person PersonOption.new.add_person nil end |
#add_task ⇒ Object (private)
method to add a new Task defined by the users console input
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/menu/entity_addition.rb', line 48 def add_task t = create_task_from_input puts "Task with id #{t.id} created successfully.".green person_id = get_entry("Enter id of the person who should take the task: ").to_i Menu.data_handler.add_task_to_person(person_id, t) puts "Task with id #{t.id} added to person with id #{person_id}.".green nil end |
#create_task_from_input ⇒ Task (private)
method to create a task from the provided input
61 62 63 64 65 66 67 68 69 |
# File 'lib/menu/entity_addition.rb', line 61 def create_task_from_input start_time = Menu.parse_date( get_entry("Enter start date (format: YYYY-MM-DD-hh:mm): ")) end_time = Menu.parse_date( get_entry("Enter end date (format: YYYY-MM-DD-hh:mm): ")) description = get_entry("Enter description: ") Task::Task.new(start_time, end_time, description) end |
#define_menu_items ⇒ Object (private)
method to define all printable menu items
15 16 17 18 19 20 21 |
# File 'lib/menu/entity_addition.rb', line 15 def ("Add person.", 1) ("Add task.", 2) ("Persist data and return to previous menu.", 3) ("Cancel and return to previous menu.", 4) nil end |
#determine_action(input) ⇒ Boolean (private)
method to process the provided input
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/menu/entity_addition.rb', line 27 def determine_action(input) case (input.to_i) when 1 then add_person when 2 then add_task when 3 Menu.data_handler.persist_data return false when 4 then return false else handle_wrong_option end return true end |