Module: Csvbuilder::Import::Base

Extended by:
ActiveSupport::Concern
Included in:
Csvbuilder::Import
Defined in:
lib/csvbuilder/importer/concerns/import/base.rb

Instance Method Summary collapse

Instance Method Details

#abort?Boolean

Safe to override.

Returns:

  • (Boolean)

    returns true, if the entire csv file should stop reading



53
54
55
# File 'lib/csvbuilder/importer/concerns/import/base.rb', line 53

def abort?
  false
end

#free_previousObject

Free ‘previous` from memory to avoid making a linked list



38
39
40
41
# File 'lib/csvbuilder/importer/concerns/import/base.rb', line 38

def free_previous
  attributes
  @previous = nil
end

#initialize(source_row_or_exception = [], options = {}) ⇒ Object

Parameters:

  • source_row_or_exception (Array) (defaults to: [])

    the csv row

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :index (Integer)

    1st row_model is 0, 2nd is 1, 3rd is 2, etc.

  • :line_number (Integer)

    line_number in the CSV file

  • :source_headers (Array)

    the csv header row

  • :previous (Csvbuilder::Import)

    the previous row model

  • :parent (Csvbuilder::Import)

    if the instance is a child, pass the parent



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/csvbuilder/importer/concerns/import/base.rb', line 21

def initialize(source_row_or_exception = [], options = {})
  @source_row     = source_row_or_exception
  @csv_exception  = source_row if source_row.is_a? Exception
  @source_row     = [] if source_row_or_exception.class != Array

  @line_number    = options[:line_number]
  @index          = options[:index]
  @source_headers = options[:source_headers]

  @previous       = options[:previous].try(:dup)

  previous.try(:free_previous)

  super(options)
end

#skip?Boolean

Safe to override.

Returns:

  • (Boolean)

    returns true, if this instance should be skipped



46
47
48
# File 'lib/csvbuilder/importer/concerns/import/base.rb', line 46

def skip?
  !valid?
end