Class: ConfigurationMenu
- Inherits:
-
Object
- Object
- ConfigurationMenu
- Defined in:
- lib/configuration/configuration_menu.rb
Overview
helper class to deliver a simple terminal menu to provide values for the available configuration parameter
Instance Method Summary collapse
-
#check_dimension_value(input) ⇒ Object
private
checks if the input for the y-dimension lies within acceptable boundaries.
-
#get_entry(message) ⇒ String
private
method to print a message and read the following input.
-
#print_menu ⇒ Object
public entry point for the configuration menu.
-
#process_boolean_input(input, symbol) ⇒ Boolean
private
method to precess the input for a boolean parameter.
-
#process_input(input) ⇒ boolean
private
method to check the input and proceed depending on its value.
-
#process_legend_input(input) ⇒ boolean
private
method to process the parameter for the extended legend option.
-
#process_scale_input(input) ⇒ Boolean
private
method to obtain the input for the scale option.
-
#process_ydim_input(input) ⇒ boolean
private
method to process the parameter for the y dimension option.
-
#save_to_file(filename) ⇒ boolean
private
method to save the currently defined options to a file.
Instance Method Details
#check_dimension_value(input) ⇒ Object (private)
checks if the input for the y-dimension lies within acceptable boundaries
73 74 75 76 77 78 |
# File 'lib/configuration/configuration_menu.rb', line 73 def check_dimension_value(input) if (input <= 0 || input > 100) raise ArgumentError, " Error: y_dim value #{input} runs out of bound [1,100]".red end end |
#get_entry(message) ⇒ String (private)
method to print a message and read the following input
119 120 121 122 |
# File 'lib/configuration/configuration_menu.rb', line 119 def get_entry() print .blue.bright gets.chomp end |
#print_menu ⇒ Object
public entry point for the configuration menu
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/configuration/configuration_menu.rb', line 13 def is_running = true # necessary to clear the script parameter, which has already been # processed by the parameter_repository ARGF.argv.clear while(is_running) puts 'Configuration Menu. Select parameter:'.light_yellow puts '(1) Extended data legend.' puts '(2) Determine y-resolution for timeline.' puts '(3) Use scaled output.' puts '(4) Save parameters to file.' puts '(5) Exit.' is_running = process_input(get_entry('Input (1-5): '.blue.bright).to_i) end end |
#process_boolean_input(input, symbol) ⇒ Boolean (private)
method to precess the input for a boolean parameter
91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/configuration/configuration_menu.rb', line 91 def process_boolean_input(input, symbol) case input when 0 then TerminalVis::option_handler.. change_option(symbol, false) when 1 then TerminalVis::option_handler.. change_option(symbol, true) else puts ' Error: Input is not valid.'.red end return true end |
#process_input(input) ⇒ boolean (private)
method to check the input and proceed depending on its value
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/configuration/configuration_menu.rb', line 35 def process_input(input) case input when 1 then return process_legend_input( get_entry('Input value (0: false, 1:true) : ').to_i) when 2 then return process_ydim_input(get_entry('Input value: ').to_i) when 3 then return process_scale_input( get_entry('Input value (0: false, 1:true) : ').to_i) when 4 then return save_to_file(get_entry('Save destination: ')) when 5 then return false else puts ' Error: Input is not valid.'.red return true end end |
#process_legend_input(input) ⇒ boolean (private)
method to process the parameter for the extended legend option
53 54 55 |
# File 'lib/configuration/configuration_menu.rb', line 53 def process_legend_input(input) process_boolean_input(input, :legend_extend) end |
#process_scale_input(input) ⇒ Boolean (private)
method to obtain the input for the scale option
83 84 85 |
# File 'lib/configuration/configuration_menu.rb', line 83 def process_scale_input(input) process_boolean_input(input, :auto_scale) end |
#process_ydim_input(input) ⇒ boolean (private)
method to process the parameter for the y dimension option
60 61 62 63 64 65 66 67 68 |
# File 'lib/configuration/configuration_menu.rb', line 60 def process_ydim_input(input) begin check_dimension_value(input) TerminalVis::option_handler..change_option(:y_time_size, input) rescue ArgumentError => e puts e. end return true end |
#save_to_file(filename) ⇒ boolean (private)
method to save the currently defined options to a file
106 107 108 109 110 111 112 113 114 |
# File 'lib/configuration/configuration_menu.rb', line 106 def save_to_file(filename) begin TerminalVis::option_handler.(filename) puts "Saved options to #{filename}".green rescue StandardError => e puts ' Error while saving options: '.concat(e.).red end return true end |