Class: CsvMapper::Importer

Inherits:
Object
  • Object
show all
Defined in:
lib/csv_mapper/importer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params, options) ⇒ Importer

Returns a new instance of Importer.



7
8
9
10
11
12
13
14
15
# File 'lib/csv_mapper/importer.rb', line 7

def initialize(params, options)
  @file_handler = CsvMapper::FileHandler.new()

  if @file_handler.save_temp_file(params[options[:file_field]])
    set_attributes_from_valid_file(options)
  else
    raise CsvMapper::MissingFileContentsError
  end
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



4
5
6
# File 'lib/csv_mapper/importer.rb', line 4

def filename
  @filename
end

#map_fieldsObject (readonly)

Returns the value of attribute map_fields.



4
5
6
# File 'lib/csv_mapper/importer.rb', line 4

def map_fields
  @map_fields
end

Instance Method Details

#raw_dataObject



17
18
19
# File 'lib/csv_mapper/importer.rb', line 17

def raw_data
  FasterCSV.read(@file_handler.file_path, CsvMapper.options)
end