def parse
      response  = { errors: 0, status: 200, total_rows: 0, error_rows: []}
      index = 0
      batch = []

      begin
        CSV.foreach("#{@file_path}/#{@csv_file_name}", :encoding => 'iso-8859-1:UTF-8', headers: true) do |row|
          index += 1
          row_hash = row.to_hash
          response[:total_rows] += 1
          begin
            record, response[:errors], error_row = validate_record(response[:errors], row_hash, index)
            response[:error_rows] << error_row if error_row
              
            if @batch_process
              batch = add_to_batch(batch, record)
            else
              record.save!
            end
          rescue Exception => e
            response[:errors] +=1
            response[:error_rows] << log_and_return_error(row_hash, e, index)
          end
        end
        import_from_batch(batch)
      rescue Exception => e
        response[:errors] = 1
        response[:error_rows] = log_and_return_error({}, e, '')
        response[:status] = 500
      end

      if response[:error_rows].blank?
        post_parse_success_calls 
      elsif @error_file_needed
        error_in_upload(response[:error_rows])
      end

      response
    end
def parse
      response  = { errors: 0, status: 200, total_rows: 0, error_rows: []}
      index = 0
      batch = []

      begin
        CSV.foreach("#{@file_path}/#{@csv_file_name}", :encoding => 'iso-8859-1:UTF-8', headers: true) do |row|
          index += 1
          row_hash = row.to_hash
          response[:total_rows] += 1
          begin
            record, response[:errors], error_row = validate_record(response[:errors], row_hash, index)
            response[:error_rows] << error_row if error_row
              
            if @batch_process
              batch = add_to_batch(batch, record)
            else
              record.save!
            end
          rescue Exception => e
            response[:errors] +=1
            response[:error_rows] << log_and_return_error(row_hash, e, index)
          end
        end
        import_from_batch(batch)
      rescue Exception => e
        response[:errors] = 1
        response[:error_rows] = log_and_return_error({}, e, '')
        response[:status] = 500
      end

      if response[:error_rows].blank?
        post_parse_success_calls 
      elsif @error_file_needed
        error_in_upload(response[:error_rows])
      end

      response
    end
parses the csv file, creates record for the model and returns response hash,e.g.
 \{:errors=>1, :status=>200, :total_rows=>4, :error_rows=>[["Test1", nil, "is invalid"]]\}
 also, it creates error file to consume