class CsvFastImporter::Configuration

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

Attributes

file[RW]

Public Class Methods

new(file, parameters = {}) click to toggle source
# File lib/csv_fast_importer/configuration.rb, line 9
def initialize(file, parameters = {})
  @file = file
  @parameters = parameters
end

Public Instance Methods

column_separator() click to toggle source
# File lib/csv_fast_importer/configuration.rb, line 18
def column_separator
  @column_separator ||= @parameters[:col_sep] || ';'
end
deletion?() click to toggle source
# File lib/csv_fast_importer/configuration.rb, line 46
def deletion?
  @deletion ||= !(@parameters[:deletion] == :none)
end
destination_table() click to toggle source
# File lib/csv_fast_importer/configuration.rb, line 26
def destination_table
  @destination_table ||= (@parameters[:destination] || File.basename(@file, '.*'))
end
encoding() click to toggle source
# File lib/csv_fast_importer/configuration.rb, line 14
def encoding
  @encoding ||= @parameters[:encoding] || 'UTF-8'
end
mapping() click to toggle source
# File lib/csv_fast_importer/configuration.rb, line 22
def mapping
  @mapping ||= downcase_keys_and_values(@parameters[:mapping] || {})
end
row_index_column() click to toggle source
# File lib/csv_fast_importer/configuration.rb, line 30
def row_index_column
  @row_index_column ||= @parameters[:row_index_column]
end
transactional?() click to toggle source
# File lib/csv_fast_importer/configuration.rb, line 34
def transactional?
  @transactional ||= !(@parameters[:transaction] == :disabled)
end
transactional_forced?() click to toggle source
# File lib/csv_fast_importer/configuration.rb, line 38
def transactional_forced?
  @transactional_forced ||= (@parameters[:transaction] == :enabled)
end
truncate?() click to toggle source
# File lib/csv_fast_importer/configuration.rb, line 42
def truncate?
  @deletion ||= @parameters[:deletion] == :truncate
end

Private Instance Methods

downcase_keys_and_values(hash) click to toggle source
# File lib/csv_fast_importer/configuration.rb, line 52
def downcase_keys_and_values(hash)
  Hash[hash.map{ |k, v| [k.to_s.downcase, v.to_s.downcase] }]
end