Class: Menu::MainMenu

Inherits:
Base
  • Object
show all
Includes:
Listenable
Defined in:
lib/menu/main_menu.rb

Overview

menu class that inherits Base to abstract the main menu

Instance Attribute Summary

Attributes inherited from Base

#menu_description, #menu_items

Instance Method Summary collapse

Methods included from Listenable

#add_listener, #listeners, #notify_listeners, #remove_listener

Methods inherited from Base

#add_menu_item, #get_entry, #handle_wrong_option, #print_menu

Constructor Details

#initializeMainMenu

initialization



11
12
13
14
# File 'lib/menu/main_menu.rb', line 11

def initialize
  super
  @menu_description = "Main menu. Select operation:"
end

Instance Method Details

#define_menu_itemsObject (private)

implementation to define the items of the menu



19
20
21
22
23
24
# File 'lib/menu/main_menu.rb', line 19

def define_menu_items
  add_menu_item("Create or change index.", 1)
  add_menu_item("Print an index.", 2)
  add_menu_item("Generate bar chart.", 3)
  add_menu_item("Quit.", 4)
end

#determine_action(input) ⇒ Object (private)

method to specify the actions to a given input

Parameters:

  • input (String)

    the user input



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

def determine_action(input)
  case (input.to_i)
    when 1 then prepare_menu(Menu::IndexOverviewMenu.new())
    when 2 then prepare_menu(Menu::IndexOutputMenu.new())
    when 3 then prepare_menu(Menu::DiagramMenu.new())
    when 4
      puts "Shutting down. Goodbye ...".yellow
      exit(0)
  end
end

#prepare_menu(menu) ⇒ Object (private)

method to register the listener to a given menu and print its items

Parameters:



41
42
43
44
# File 'lib/menu/main_menu.rb', line 41

def prepare_menu(menu)
  menu.add_listener(:repo_listener, listeners[:repo_listener])
  menu.print_menu
end