Class: Csvtool::Interface::CLI::MenuLoop

Inherits:
Object
  • Object
show all
Defined in:
lib/csvtool/interface/cli/menu_loop.rb

Instance Method Summary collapse

Constructor Details

#initialize(stdin:, stdout:, stderr: stdout, menu_options:, extract_column_action:, extract_rows_action:, randomize_rows_action:, dedupe_action:, parity_action:, split_action:, stats_action:) ⇒ MenuLoop

Returns a new instance of MenuLoop.



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/csvtool/interface/cli/menu_loop.rb', line 7

def initialize(stdin:, stdout:, stderr: stdout, menu_options:, extract_column_action:, extract_rows_action:, randomize_rows_action:, dedupe_action:, parity_action:, split_action:, stats_action:)
  @stdin = stdin
  @stdout = stdout
  @stderr = stderr
  @menu_options = menu_options
  @extract_column_action = extract_column_action
  @extract_rows_action = extract_rows_action
  @randomize_rows_action = randomize_rows_action
  @dedupe_action = dedupe_action
  @parity_action = parity_action
  @split_action = split_action
  @stats_action = stats_action
end

Instance Method Details

#runObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/csvtool/interface/cli/menu_loop.rb', line 21

def run
  loop do
    print_menu
    @stderr.print "> "
    choice = @stdin.gets
    return 0 if choice.nil?

    case choice.strip
    when "1"
      @extract_column_action.call
    when "2"
      @extract_rows_action.call
    when "3"
      @randomize_rows_action.call
    when "4"
      @dedupe_action.call
    when "5"
      @parity_action.call
    when "6"
      @split_action.call
    when "7"
      @stats_action.call
    when "8"
      return 0
    else
      @stderr.puts "Please choose 1, 2, 3, 4, 5, 6, 7, or 8."
    end
  end
end