Sha256: 4079faf4ca1ce5b033d58d1f1f504fd5ff93b239c697006541d3add4a50793e1

Contents?: true

Size: 1.01 KB

Versions: 3

Compression:

Stored size: 1.01 KB

Contents

require "awesome_print"

require "cascade/columns_matching"
require "cascade/cascade_csv"
require "cascade/row_processor"
require "cascade/error_handler"
require "cascade/helpers/hash"

module Cascade
  class DataParser
    PUTS_DATA_SAVER = ->(*args) { ap args }

    def initialize(filename, options = {})
      @filename = filename
      @data_provider    = options.fetch(:data_provider)    { CascadeCsv }
      @row_processor    = options.fetch(:row_processor)    { RowProcessor.new }
      @error_handler    = options.fetch(:error_handler)    { ErrorHandler.new }
      @data_saver       = options.fetch(:data_saver)       { PUTS_DATA_SAVER }
    end

    # Starts parsing processing with opening file and iterating through each
    # line with parsing and then saves result of each line parsing with
    # DataSaver
    #
    def call
      @data_provider.open(@filename).each do |row|
        @error_handler.with_errors_handling(row) do
          @data_saver.call @row_processor.call(row)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cascade-rb-0.1.5 lib/cascade/data_parser.rb
cascade-rb-0.1.4 lib/cascade/data_parser.rb
cascade-rb-0.1.2 lib/cascade/data_parser.rb