Class: ConfigurationMenu

Inherits:
Object
  • Object
show all
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

Instance Method Details

#check_dimension_value(input) ⇒ Object (private)

checks if the input for the y-dimension lies within acceptable boundaries

Parameters:

  • input (Integer)

    the provided input

Raises:

  • (ArgumentError)

    if the value lies outside the interval



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

Parameters:

  • message (String)

    prompt message

Returns:

  • (String)

    the provided input



119
120
121
122
# File 'lib/configuration/configuration_menu.rb', line 119

def get_entry(message)
  print message.blue.bright
  gets.chomp
end

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 print_menu
  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

Parameters:

  • input (Integer)

    the provided input

  • symbol (Symbol)

    the hash key for the options menu

Returns:

  • (Boolean)

    true to mark the successful handling of the input



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.options.
                           change_option(symbol, false)
  when 1 then TerminalVis::option_handler.options.
                           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

Parameters:

  • input (Integer)

    the provided input

Returns:

  • (boolean)

    as an indicator if the configuration is finished



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

Parameters:

  • input (Integer)

    the provided parameter

Returns:

  • (boolean)

    true if the parameter was processed correctly



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

Parameters:

  • input (Integer)

    the provided input

Returns:

  • (Boolean)

    true to mark the successful handling of the input



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

Parameters:

  • input (Integer)

    the provided parameter

Returns:

  • (boolean)

    true if the parameter was processed correctly



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.options.change_option(:y_time_size, input)
  rescue ArgumentError => e
    puts e.message
  end
  return true
end

#save_to_file(filename) ⇒ boolean (private)

method to save the currently defined options to a file

Parameters:

  • filename (String)

    the filename of the output file

Returns:

  • (boolean)

    true if the options were saved correctly



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.save_options(filename)
    puts "Saved options to #{filename}".green
  rescue StandardError => e
    puts ' Error while saving options: '.concat(e.message).red
  end
  return true
end