Class: Csvtool::Interface::CLI::Prompts::DedupeKeySelectorPrompt

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

Instance Method Summary collapse

Constructor Details

#initialize(stdin:, stdout:) ⇒ DedupeKeySelectorPrompt

Returns a new instance of DedupeKeySelectorPrompt.



10
11
12
13
# File 'lib/csvtool/interface/cli/prompts/dedupe_key_selector_prompt.rb', line 10

def initialize(stdin:, stdout:)
  @stdin = stdin
  @stdout = stdout
end

Instance Method Details

#call(label:, headers_present:) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/csvtool/interface/cli/prompts/dedupe_key_selector_prompt.rb', line 15

def call(label:, headers_present:)
  if headers_present
    @stdout.print "#{label} key column name: "
  else
    @stdout.print "#{label} key column index (1-based): "
  end
  input = @stdin.gets&.strip.to_s
  Domain::CrossCsvDedupeSession::ColumnSelector.from_input(headers_present: headers_present, input: input)
rescue ArgumentError
  nil
end