lib/kpm/account.rb in kpm-0.6.3 vs lib/kpm/account.rb in kpm-0.6.4
- old
+ new
@@ -97,30 +97,30 @@
end
export_data = fetch_export_data(account_id)
export_file = export(export_data)
- if not File.exist?(export_file)
+ unless File.exist?(export_file)
raise Interrupt, 'Account id not found'
else
@logger.info "\e[32mData exported under #{export_file}\e[0m"
end
export_file
end
- def import_data(source_file,tenant_record_id, skip_payment_methods, round_trip_export_import = false, generate_record_id = false)
+ def import_data(source_file, tenant_record_id, skip_payment_methods, round_trip_export_import = false, generate_record_id = false)
@generate_record_id = generate_record_id
@tenant_record_id = tenant_record_id
@round_trip_export_import = round_trip_export_import
if source_file === :import.to_s
raise Interrupt, 'Need to specify a file'
end
- if not File.exist?(source_file)
+ unless File.exist?(source_file)
raise Interrupt, 'Need to specify a valid file'
end
@delimiter = sniff_delimiter(source_file) || @delimiter
@@ -217,11 +217,11 @@
data.each_line do |line|
words = line.strip.split(" ")
if /--/.match(words[0])
- if not table_name.nil?
+ unless table_name.nil?
if @generate_record_id
cols_names.shift
end
tables[table_name] = { :col_names => cols_names, :rows => rows};
@@ -254,19 +254,20 @@
if tables.empty?
error_importing_data = true
end
end
- if not error_importing_data
+ unless error_importing_data
import(tables)
else
raise Interrupt, "Data on #{source_file} is invalid"
end
end
def process_import_data(line, table_name, cols_names, skip_payment_methods, rows)
- cols = line.strip.split(@delimiter)
+ # to make sure that the last column is not omitted if is empty
+ cols = line.strip.split(@delimiter,line.count(@delimiter)+1)
if cols_names.size != cols.size
@logger.warn "\e[32mWARNING!!! On #{table_name} table there is a mismatch on column count[#{cols.size}] versus header count[#{cols_names.size}]\e[0m"
return nil
end
\ No newline at end of file