Class: ActAsImportable::CSVImporter

Inherits:
Importer
  • Object
show all
Defined in:
lib/act_as_importable/csv_importer.rb

Instance Method Summary collapse

Methods inherited from Importer

#failed_imports, #filter_columns, #import_data, #import_record, #imported_records, #initialize, #missing_uid_values, #model_class, #options, #successful_imports

Constructor Details

This class inherits a constructor from ActAsImportable::Importer

Instance Method Details

#import_csv_file(file) ⇒ Object



6
7
8
# File 'lib/act_as_importable/csv_importer.rb', line 6

def import_csv_file(file)
  import_csv_text(File.read(file, options))
end

#import_csv_text(text) ⇒ Object



10
11
12
13
14
15
# File 'lib/act_as_importable/csv_importer.rb', line 10

def import_csv_text(text)
  csv = ::CSV.parse(text, :headers => options[:headers] || true)
  csv.each do |row|
    import_record(row.to_hash)
  end
end