Class: Csvtool::Interface::CLI::Prompts::SeparatorPrompt
- Inherits:
-
Object
- Object
- Csvtool::Interface::CLI::Prompts::SeparatorPrompt
- Defined in:
- lib/csvtool/interface/cli/prompts/separator_prompt.rb
Constant Summary collapse
- DEFAULT_LABEL =
"Choose separator:"
Instance Method Summary collapse
- #call(label: DEFAULT_LABEL) ⇒ Object
-
#initialize(stdin:, stdout:, errors:) ⇒ SeparatorPrompt
constructor
A new instance of SeparatorPrompt.
Constructor Details
#initialize(stdin:, stdout:, errors:) ⇒ SeparatorPrompt
Returns a new instance of SeparatorPrompt.
10 11 12 13 14 |
# File 'lib/csvtool/interface/cli/prompts/separator_prompt.rb', line 10 def initialize(stdin:, stdout:, errors:) @stdin = stdin @stdout = stdout @errors = errors end |
Instance Method Details
#call(label: DEFAULT_LABEL) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/csvtool/interface/cli/prompts/separator_prompt.rb', line 16 def call(label: DEFAULT_LABEL) @stdout.puts label @stdout.puts "1. comma (,)" @stdout.puts "2. tab (\\t)" @stdout.puts "3. semicolon (;)" @stdout.puts "4. pipe (|)" @stdout.puts "5. custom" @stdout.print "Separator choice [1]: " case @stdin.gets&.strip.to_s when "", "1" then "," when "2" then "\t" when "3" then ";" when "4" then "|" when "5" @stdout.print "Custom separator: " custom = @stdin.gets&.strip.to_s return custom unless custom.empty? @errors.empty_custom_separator nil else @errors.invalid_separator_choice nil end end |