Class: Csvtool::Interface::CLI::Workflows::RunExtractionWorkflow

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

Instance Method Summary collapse

Constructor Details

#initialize(stdin:, stdout:, stderr: stdout, use_case: Application::UseCases::RunExtraction.new) ⇒ RunExtractionWorkflow

Returns a new instance of RunExtractionWorkflow.



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/csvtool/interface/cli/workflows/run_extraction_workflow.rb', line 26

def initialize(stdin:, stdout:, stderr: stdout, use_case: Application::UseCases::RunExtraction.new)
  @stdin = stdin
  @stdout = stdout
  @stderr = stderr
  @use_case = use_case
  @errors = Interface::CLI::Errors::Presenter.new(stdout: @stderr)
  @session_builder = Builders::ColumnSessionBuilder.new
  @presenter = Presenters::ColumnExtractionPresenter.new(stdout: @stdout)
  @output_destination_mapper = Support::OutputDestinationMapper.new
  @result_error_handler = Support::ResultErrorHandler.new(errors: @errors)
end

Instance Method Details

#callObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/csvtool/interface/cli/workflows/run_extraction_workflow.rb', line 38

def call
  context = {
    use_case: @use_case,
    session_builder: @session_builder,
    output_destination_mapper: @output_destination_mapper,
    presenter: @presenter,
    handle_error: method(:handle_error)
  }

  pipeline = Steps::WorkflowStepPipeline.new(steps: [
    Steps::Extraction::CollectInputsStep.new(
      file_path_prompt: Interface::CLI::Prompts::FilePathPrompt.new(stdin: @stdin, stdout: @stderr),
      separator_prompt: Interface::CLI::Prompts::SeparatorPrompt.new(stdin: @stdin, stdout: @stderr, errors: @errors),
      column_selector_prompt: Interface::CLI::Prompts::ColumnSelectorPrompt.new(stdin: @stdin, stdout: @stderr, errors: @errors),
      skip_blanks_prompt: Interface::CLI::Prompts::SkipBlanksPrompt.new(stdin: @stdin, stdout: @stderr)
    ),
    Steps::Extraction::BuildPreviewStep.new(
      confirm_prompt: Interface::CLI::Prompts::ConfirmPrompt.new(stdin: @stdin, stdout: @stderr, errors: @errors)
    ),
    Steps::Extraction::CollectDestinationStep.new(
      output_destination_prompt: Interface::CLI::Prompts::OutputDestinationPrompt.new(
        stdin: @stdin,
        stdout: @stderr,
        errors: @errors
      )
    ),
    Steps::Extraction::ExecuteStep.new
  ])
  pipeline.call(context)
rescue ArgumentError => e
  return @errors.empty_output_path if e.message == "file output path cannot be empty"

  raise e
end