Class: SmartCsvImport::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/smart_csv_import/result.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



10
11
12
# File 'lib/smart_csv_import/result.rb', line 10

def errors
  @errors
end

#failedObject (readonly)

Returns the value of attribute failed.



10
11
12
# File 'lib/smart_csv_import/result.rb', line 10

def failed
  @failed
end

#header_mappingsObject (readonly)

Returns the value of attribute header_mappings.



10
11
12
# File 'lib/smart_csv_import/result.rb', line 10

def header_mappings
  @header_mappings
end

#import_idObject (readonly)

Returns the value of attribute import_id.



10
11
12
# File 'lib/smart_csv_import/result.rb', line 10

def import_id
  @import_id
end

#importedObject (readonly)

Returns the value of attribute imported.



10
11
12
# File 'lib/smart_csv_import/result.rb', line 10

def imported
  @imported
end

#parse_errorsObject (readonly)

Returns the value of attribute parse_errors.



10
11
12
# File 'lib/smart_csv_import/result.rb', line 10

def parse_errors
  @parse_errors
end

#proposed_mappingsObject (readonly)

Returns the value of attribute proposed_mappings.



10
11
12
# File 'lib/smart_csv_import/result.rb', line 10

def proposed_mappings
  @proposed_mappings
end

#statusObject (readonly)

Returns the value of attribute status.



10
11
12
# File 'lib/smart_csv_import/result.rb', line 10

def status
  @status
end

#totalObject (readonly)

Returns the value of attribute total.



10
11
12
# File 'lib/smart_csv_import/result.rb', line 10

def total
  @total
end

#unmatched_columnsObject (readonly)

Returns the value of attribute unmatched_columns.



10
11
12
# File 'lib/smart_csv_import/result.rb', line 10

def unmatched_columns
  @unmatched_columns
end

#warningsObject (readonly)

Returns the value of attribute warnings.



10
11
12
# File 'lib/smart_csv_import/result.rb', line 10

def warnings
  @warnings
end

Class Method Details

.completed(imported:, failed:, total:, errors:, header_mappings:, import_id: nil, warnings: [], parse_errors: []) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/smart_csv_import/result.rb', line 16

def self.completed(imported:, failed:, total:, errors:, header_mappings:, import_id: nil, warnings: [], parse_errors: [])
  new(
    status: :completed,
    imported: imported,
    failed: failed,
    total: total,
    errors: errors,
    header_mappings: header_mappings,
    import_id: import_id,
    warnings: warnings,
    parse_errors: parse_errors
  )
end

.dry_run(imported:, failed:, total:, errors:, header_mappings:, warnings: [], parse_errors: []) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/smart_csv_import/result.rb', line 65

def self.dry_run(imported:, failed:, total:, errors:, header_mappings:, warnings: [], parse_errors: [])
  new(
    status: :dry_run,
    imported: imported,
    failed: failed,
    total: total,
    errors: errors,
    header_mappings: header_mappings,
    warnings: warnings,
    parse_errors: parse_errors
  )
end

.partial_failure(imported:, failed:, total:, errors:, header_mappings:, import_id: nil, warnings: [], parse_errors: []) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/smart_csv_import/result.rb', line 30

def self.partial_failure(imported:, failed:, total:, errors:, header_mappings:, import_id: nil, warnings: [], parse_errors: [])
  new(
    status: :partial_failure,
    imported: imported,
    failed: failed,
    total: total,
    errors: errors,
    header_mappings: header_mappings,
    import_id: import_id,
    warnings: warnings,
    parse_errors: parse_errors
  )
end

.queued(import_id:, **rest) ⇒ Object

Raises:

  • (ArgumentError)


55
56
57
58
59
60
61
62
63
# File 'lib/smart_csv_import/result.rb', line 55

def self.queued(import_id:, **rest)
  invalid_keys = rest.keys & %i[imported failed total]
  raise ArgumentError, "queued result does not accept: #{invalid_keys.join(", ")}" if invalid_keys.any?

  new(
    status: :queued,
    import_id: import_id
  )
end

.review_required(header_mappings:, import_id: nil, proposed_mappings: {}, unmatched_columns: [], warnings: []) ⇒ Object



44
45
46
47
48
49
50
51
52
53
# File 'lib/smart_csv_import/result.rb', line 44

def self.review_required(header_mappings:, import_id: nil, proposed_mappings: {}, unmatched_columns: [], warnings: [])
  new(
    status: :review_required,
    header_mappings: header_mappings,
    import_id: import_id,
    proposed_mappings: proposed_mappings,
    unmatched_columns: unmatched_columns,
    warnings: warnings
  )
end

Instance Method Details

#completed?Boolean

Returns:

  • (Boolean)


78
# File 'lib/smart_csv_import/result.rb', line 78

def completed? = status == :completed

#dry_run?Boolean

Returns:

  • (Boolean)


82
# File 'lib/smart_csv_import/result.rb', line 82

def dry_run? = status == :dry_run

#partial_failure?Boolean

Returns:

  • (Boolean)


79
# File 'lib/smart_csv_import/result.rb', line 79

def partial_failure? = status == :partial_failure

#queued?Boolean

Returns:

  • (Boolean)


81
# File 'lib/smart_csv_import/result.rb', line 81

def queued? = status == :queued

#review_required?Boolean

Returns:

  • (Boolean)


80
# File 'lib/smart_csv_import/result.rb', line 80

def review_required? = status == :review_required

#success?Boolean

Returns:

  • (Boolean)


83
# File 'lib/smart_csv_import/result.rb', line 83

def success? = completed? && errors.empty?