Class: Menu::Base
- Inherits:
-
Object
- Object
- Menu::Base
- Defined in:
- lib/menu/base.rb
Overview
Menu main class
Instance Method Summary collapse
- #create_input_map ⇒ Object
- #create_procs_map ⇒ Object
-
#initialize(menu, input_map = {}, procs_map = {}) ⇒ Base
constructor
Initialize a new menu.
-
#run_default ⇒ Object
Print help.
-
#run_selected_command(input, procs) ⇒ Object
Run user's selected command.
Constructor Details
#initialize(menu, input_map = {}, procs_map = {}) ⇒ Base
Initialize a new menu
26 27 28 29 30 31 |
# File 'lib/menu/base.rb', line 26 def initialize(, input_map = {}, procs_map = {}) self. = run_selected_command(create_input_map.merge(input_map), create_procs_map.merge(procs_map)) end |
Instance Method Details
#create_input_map ⇒ Object
35 |
# File 'lib/menu/base.rb', line 35 def create_input_map; end |
#create_procs_map ⇒ Object
33 |
# File 'lib/menu/base.rb', line 33 def create_procs_map; end |
#run_default ⇒ Object
Print help
49 50 51 |
# File 'lib/menu/base.rb', line 49 def run_default puts end |
#run_selected_command(input, procs) ⇒ Object
Run user's selected command
38 39 40 41 42 43 44 45 46 |
# File 'lib/menu/base.rb', line 38 def run_selected_command(input, procs) selected_key = input.keys.select { |key| input[key] }.first if selected_key.nil? run_default return end procs[selected_key].call end |