Class: Csvtool::Interface::CLI::Workflows::Steps::CsvSplit::CollectInputsStep

Inherits:
Object
  • Object
show all
Defined in:
lib/csvtool/interface/cli/workflows/steps/csv_split/collect_inputs_step.rb

Instance Method Summary collapse

Constructor Details

#initialize(file_path_prompt:, separator_prompt:, headers_present_prompt:, chunk_size_prompt:, errors:) ⇒ CollectInputsStep

Returns a new instance of CollectInputsStep.



10
11
12
13
14
15
16
# File 'lib/csvtool/interface/cli/workflows/steps/csv_split/collect_inputs_step.rb', line 10

def initialize(file_path_prompt:, separator_prompt:, headers_present_prompt:, chunk_size_prompt:, errors:)
  @file_path_prompt = file_path_prompt
  @separator_prompt = separator_prompt
  @headers_present_prompt = headers_present_prompt
  @chunk_size_prompt = chunk_size_prompt
  @errors = errors
end

Instance Method Details

#call(context) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/csvtool/interface/cli/workflows/steps/csv_split/collect_inputs_step.rb', line 18

def call(context)
  context[:file_path] = @file_path_prompt.call(label: "Source CSV file path: ")
  col_sep = @separator_prompt.call
  return :halt if col_sep.nil?

  context[:col_sep] = col_sep
  context[:headers_present] = @headers_present_prompt.call
  chunk_size = Integer(@chunk_size_prompt.call)
  if chunk_size <= 0
    @errors.invalid_chunk_size
    return :halt
  end

  context[:chunk_size] = chunk_size
  nil
rescue ArgumentError, TypeError
  @errors.invalid_chunk_size
  :halt
end