Class: CsvFastImporter::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/csv_fast_importer/configuration.rb

Overview

Gather all import configurations based on given file and additional parameters. This class is also responsible for default configuration.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, parameters = {}) ⇒ Configuration

Returns a new instance of Configuration.



9
10
11
12
# File 'lib/csv_fast_importer/configuration.rb', line 9

def initialize(file, parameters = {})
  @file = file
  @parameters = parameters
end

Instance Attribute Details

#fileObject

Returns the value of attribute file.



7
8
9
# File 'lib/csv_fast_importer/configuration.rb', line 7

def file
  @file
end

Instance Method Details

#column_separatorObject



18
19
20
# File 'lib/csv_fast_importer/configuration.rb', line 18

def column_separator
  @column_separator ||= @parameters[:col_sep] || ';'
end

#deletion?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/csv_fast_importer/configuration.rb', line 46

def deletion?
  @deletion ||= !(@parameters[:deletion] == :none)
end

#destination_tableObject



26
27
28
# File 'lib/csv_fast_importer/configuration.rb', line 26

def destination_table
  @destination_table ||= (@parameters[:destination] || File.basename(@file, '.*'))
end

#encodingObject



14
15
16
# File 'lib/csv_fast_importer/configuration.rb', line 14

def encoding
  @encoding ||= @parameters[:encoding] || 'UTF-8'
end

#mappingObject



22
23
24
# File 'lib/csv_fast_importer/configuration.rb', line 22

def mapping
  @mapping ||= downcase_keys_and_values(@parameters[:mapping] || {})
end

#row_index_columnObject



30
31
32
# File 'lib/csv_fast_importer/configuration.rb', line 30

def row_index_column
  @row_index_column ||= @parameters[:row_index_column]
end

#transactional?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/csv_fast_importer/configuration.rb', line 34

def transactional?
  @transactional ||= !(@parameters[:transaction] == :disabled)
end

#transactional_forced?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/csv_fast_importer/configuration.rb', line 38

def transactional_forced?
  @transactional_forced ||= (@parameters[:transaction] == :enabled)
end

#truncate?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/csv_fast_importer/configuration.rb', line 42

def truncate?
  @deletion ||= @parameters[:deletion] == :truncate
end