Class: Menu::AdapterMenu

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

Overview

menu class to select the storage adapter that should be used

Instance Attribute Summary collapse

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

#initialize(filename) ⇒ AdapterMenu

initialization



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

def initialize(filename)
  super
  @menu_description = "\nSelect database adapter:"
  @filename = filename
end

Instance Attribute Details

#filenameString (readonly, private)

Returns the storage path.

Returns:

  • (String)

    the storage path



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

def filename
  @filename
end

Instance Method Details

#define_menu_itemsObject (private)

method to define all printable menu items



19
20
21
22
# File 'lib/menu/adapter_menu.rb', line 19

def define_menu_items
  add_menu_item("File storage.", 1)
  add_menu_item("Sqlite3.", 2)
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



28
29
30
31
32
33
34
35
36
# File 'lib/menu/adapter_menu.rb', line 28

def determine_action(input)
  case (input.to_i)
    when 1 then set_data_handler(DataHandler::FileHandler.new(@filename))
    when 2 then set_data_handler(DataHandler::SqliteHandler.new(@filename))
  else
    handle_wrong_option
  end
  false
end

#set_data_handler(data_handler) ⇒ Object (private)

method to set the selected data handler @param data_handler the select storage handler



40
41
42
43
# File 'lib/menu/adapter_menu.rb', line 40

def set_data_handler(data_handler)
  Menu.initialize_datahandler(data_handler)
  nil
end