Class: Csvtool::Interface::CLI::Workflows::Steps::RowExtraction::ExecuteStep
- Inherits:
-
Object
- Object
- Csvtool::Interface::CLI::Workflows::Steps::RowExtraction::ExecuteStep
- Defined in:
- lib/csvtool/interface/cli/workflows/steps/row_extraction/execute_step.rb
Instance Method Summary collapse
- #call(context) ⇒ Object
-
#initialize(stdout:, errors:, presenter_class: Presenters::RowExtractionPresenter) ⇒ ExecuteStep
constructor
A new instance of ExecuteStep.
Constructor Details
#initialize(stdout:, errors:, presenter_class: Presenters::RowExtractionPresenter) ⇒ ExecuteStep
Returns a new instance of ExecuteStep.
10 11 12 13 14 |
# File 'lib/csvtool/interface/cli/workflows/steps/row_extraction/execute_step.rb', line 10 def initialize(stdout:, errors:, presenter_class: Presenters::RowExtractionPresenter) @stdout = stdout @errors = errors @presenter_class = presenter_class end |
Instance Method Details
#call(context) ⇒ Object
16 17 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/row_extraction/execute_step.rb', line 16 def call(context) session = context.fetch(:session) presenter = @presenter_class.new( stdout: @stdout, headers: context.fetch(:headers), col_sep: "," ) result = context.fetch(:use_case).extract( session: session, headers: context.fetch(:headers), on_row: ->(fields) { presenter.print_row(fields) } ) unless result.ok? context.fetch(:handle_error).call(result) return :halt end presenter.print_file_written(result.data[:output_path]) if result.data[:wrote_rows] @errors.row_range_out_of_bounds(result.data[:row_count]) unless result.data[:matched] nil end |