Sha256: fb7a07a9ad6e46609b37b7a35a5f61c5dfba8b69b8b748a3b0237103651b4fd1

Contents?: true

Size: 653 Bytes

Versions: 1

Compression:

Stored size: 653 Bytes

Contents

module DataImporter
  class ImporterService
    attr_accessor :reader, :report, :klass

    def initialize(file_name, klass, mappings=nil, required_keys=[])
      @klass = klass
      @report = Report.new
      @reader = CsvReader.new(file_name, mappings)
    end

    def run
      @report.time_elapsed = Benchmark.realtime do
        while row = @reader.get_mapped_row_hash
          new_entry = @klass.new(row)
          if new_entry.save
            @report.successful += 1
          else
            @report.unsuccessful += 1
          end
          @report.total = @report.successful + @report.unsuccessful
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
data_importer-0.1.0 lib/data_importer/importer_service.rb