Class: Rails::Contact::Csv::ImportService
- Inherits:
-
Object
- Object
- Rails::Contact::Csv::ImportService
- Defined in:
- lib/rails/contact/csv/import_service.rb
Constant Summary collapse
- HEADER_MAP =
{ "Enquirer First Name" => :given_name, "Enquirer Last Name" => :family_name, "Current City" => :current_city, "Departure City" => :departure_city, "Region Name" => :region_name }.freeze
Instance Method Summary collapse
- #import! ⇒ Object
-
#initialize(path:, dedupe_key: :email) ⇒ ImportService
constructor
A new instance of ImportService.
Constructor Details
#initialize(path:, dedupe_key: :email) ⇒ ImportService
Returns a new instance of ImportService.
15 16 17 18 |
# File 'lib/rails/contact/csv/import_service.rb', line 15 def initialize(path:, dedupe_key: :email) @path = path @dedupe_key = dedupe_key end |
Instance Method Details
#import! ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/rails/contact/csv/import_service.rb', line 20 def import! imported = 0 CSV.foreach(@path, headers: true) do |row| import_row(row.to_h) imported += 1 end imported end |