Class: MrCommon::PreRegistrationImporter

Inherits:
Object
  • Object
show all
Defined in:
app/models/mr_common/pre_registration_importer.rb

Overview

Imports PreRegistration records from a CSV file that looks like:

first_name, last_name, email
John, Smith, [email protected]
Jane, Doe, [email protected]
,,[email protected]
Name,Only,

Author:

Defined Under Namespace

Classes: ResultStruct, RowStruct

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(csv) ⇒ PreRegistrationImporter

Returns a new instance of PreRegistrationImporter.

Parameters:

  • csv (String)

    a the contents of a CSV file



27
28
29
30
31
# File 'app/models/mr_common/pre_registration_importer.rb', line 27

def initialize(csv)
  @csv = csv
  @created = 0
  @skipped = 0
end

Instance Attribute Details

#csvObject (readonly)

Returns the value of attribute csv.



24
25
26
# File 'app/models/mr_common/pre_registration_importer.rb', line 24

def csv
  @csv
end

#current_rowObject (readonly)

Returns the value of attribute current_row.



24
25
26
# File 'app/models/mr_common/pre_registration_importer.rb', line 24

def current_row
  @current_row
end

#resultObject (readonly)

Returns the value of attribute result.



24
25
26
# File 'app/models/mr_common/pre_registration_importer.rb', line 24

def result
  @result
end

Instance Method Details

#importObject

Attempts to create PreRegistration records for each row in the CSV recording the number of created and skipped records in the process.

The result is memoized to prevent double imports.



39
40
41
# File 'app/models/mr_common/pre_registration_importer.rb', line 39

def import
  @result ||= perform_import
end