Class: DataSeeder::Loader::CSV

Inherits:
Object
  • Object
show all
Includes:
DataSeeder::Loader
Defined in:
lib/data_seeder/loader/csv.rb

Instance Attribute Summary

Attributes included from DataSeeder::Loader

#file_config, #key_attribute, #path, #path_minus_ext

Instance Method Summary collapse

Methods included from DataSeeder::Loader

#call_file_method, #config, #initialize, #klass, #load_file_config, #logger, #model_info, #process, #save, #save_model, #setup, #teardown

Instance Method Details

#line_numberObject



8
9
10
11
# File 'lib/data_seeder/loader/csv.rb', line 8

def line_number
  # Don't count the header
  $INPUT_LINE_NUMBER-1
end

#load(io) ⇒ Object



13
14
15
16
17
# File 'lib/data_seeder/loader/csv.rb', line 13

def load(io)
  ::CSV.foreach(io, headers: true) do |row|
    save(row.to_hash)
  end
end