Class: Menu::EntityQueries
Overview
Instance Attribute Summary
Attributes inherited from Base
#menu_description, #menu_items
Instance Method Summary collapse
-
#define_menu_items ⇒ Object
private
method to define all printable menu items.
-
#determine_action(input) ⇒ Boolean
private
method to process the provided input.
-
#initialize ⇒ EntityQueries
constructor
initialization.
-
#output_results(results) ⇒ Object
private
method to print a given array of result entities.
-
#query_all_persons ⇒ Object
private
method to query all persons of the database.
-
#query_all_tasks ⇒ Object
private
method to query all tasks of the database.
-
#query_person ⇒ Object
private
method to query a person from the database by id.
-
#query_task ⇒ Object
private
method to query a task from the database by its id.
-
#query_tasks_to_person ⇒ Object
private
method to query all tasks belonging to a specified person.
Methods inherited from Base
#add_menu_item, #get_entry, #handle_wrong_option, #print_menu
Constructor Details
#initialize ⇒ EntityQueries
initialization
7 8 9 10 |
# File 'lib/menu/entity_queries.rb', line 7 def initialize super @menu_description = "Person and Task Queries" end |
Instance Method Details
#define_menu_items ⇒ Object (private)
method to define all printable menu items
15 16 17 18 19 20 21 22 23 |
# File 'lib/menu/entity_queries.rb', line 15 def ("Query person.", 1) ("Query task.", 2) ("Query tasks to person.", 3) ("Query persons.", 4) ("Query tasks.", 5) ("Cancel and return to previous menu.", 6) nil end |
#determine_action(input) ⇒ Boolean (private)
method to process the provided input
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/menu/entity_queries.rb', line 29 def determine_action(input) case (input.to_i) when 1 then query_person when 2 then query_task when 3 then query_tasks_to_person when 4 then query_all_persons when 5 then query_all_tasks when 6 then return false else handle_wrong_option end return true end |
#output_results(results) ⇒ Object (private)
method to print a given array of result entities
92 93 94 95 96 97 |
# File 'lib/menu/entity_queries.rb', line 92 def output_results(results) results.each { |result| puts result.to_string } nil end |
#query_all_persons ⇒ Object (private)
method to query all persons of the database
57 58 59 60 |
# File 'lib/menu/entity_queries.rb', line 57 def query_all_persons output_results(Menu.data_handler.get_persons) nil end |
#query_all_tasks ⇒ Object (private)
method to query all tasks of the database
63 64 65 66 |
# File 'lib/menu/entity_queries.rb', line 63 def query_all_tasks output_results(Menu.data_handler.get_tasks) nil end |
#query_person ⇒ Object (private)
method to query a person from the database by id
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/menu/entity_queries.rb', line 45 def query_person begin id = get_entry("Enter id: ").to_i p = Menu.data_handler.find_person_by_id(id) puts "Result: #{p.to_string}\n\n" rescue NoMethodError puts "Could not found person with id #{id}.".red end nil end |
#query_task ⇒ Object (private)
method to query a task from the database by its id
69 70 71 72 73 74 |
# File 'lib/menu/entity_queries.rb', line 69 def query_task id = get_entry("Enter id: ").to_i task = Menu.data_handler.find_task_to_id(id) puts task.to_string nil end |
#query_tasks_to_person ⇒ Object (private)
method to query all tasks belonging to a specified person
77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/menu/entity_queries.rb', line 77 def query_tasks_to_person begin id = get_entry("Enter id: ").to_i t = Menu.data_handler.get_tasks_to_person(id) puts "#{t.size} tasks found".yellow output_results(t) puts rescue NoMethodError puts "Could not found person with id #{id}.".red end nil end |