Class: Menu::DatabaseOption

Inherits:
Base
  • Object
show all
Defined in:
lib/menu/database_option.rb

Overview

This class holds the menu for query options regarding person and task query and the addition of people or tasks

Instance Attribute Summary

Attributes inherited from Base

#menu_description, #menu_items

Instance Method Summary collapse

Methods inherited from Base

#add_menu_item, #get_entry, #handle_wrong_option, #print_menu

Constructor Details

#initializeDatabaseOption

initialization



8
9
10
11
# File 'lib/menu/database_option.rb', line 8

def initialize
  super
  @menu_description = "\nDatabase options"
end

Instance Method Details

#database_menuObject

main entry point, this method gets the DataHandler from the MainMenu to work on the repository and to initiate the save operation



15
16
17
18
# File 'lib/menu/database_option.rb', line 15

def database_menu
  Query.initialize_repository(Menu.data_handler)
  print_menu
end

#define_menu_itemsObject (private)

method to define all printable menu items



23
24
25
26
27
28
29
# File 'lib/menu/database_option.rb', line 23

def define_menu_items
  add_menu_item("Add entity.", 1)
  add_menu_item("Query entities.", 2)
  add_menu_item("Query worktime.", 3)
  add_menu_item("Save and exit.", 4)
  add_menu_item("Abort and exit.", 5)
end

#determine_action(input) ⇒ Boolean (private)

method to process the provided input

Parameters:

  • input (String)

    the provided input

Returns:

  • (Boolean)

    true: if the program should continue, false: if the script should exit



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/menu/database_option.rb', line 35

def determine_action(input)
  case (input.to_i)
    when 1 then EntityAddition.new.print_menu
    when 2 then EntityQueries.new.print_menu
    when 3 then WorktimeQueries.new.print_menu
    when 4 then save_and_exit
    when 5 then Menu.exit_script
  else
    handle_wrong_option
  end
  return true
end

#save_and_exitObject (private)

method to save the current repository and exit the script



49
50
51
52
53
54
55
56
# File 'lib/menu/database_option.rb', line 49

def save_and_exit
  begin
    Menu.data_handler.persist_data
    Menu.exit_script
  rescue IOError => e
    raise IOError, "Error while saving data: ".concat(e.message).red
  end
end