csv_migration 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/csv_migration.rb +18 -8
  3. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 00f06e4a49f53bb66702884ad4ab06c5fa41bfb15c69e1eb6d637bf4fb9d0281
4
- data.tar.gz: 6e667978527a2a0b55899315d3b1d98b4aa0e05e52eacdec961ae1efd67e2cf8
3
+ metadata.gz: d180b6a00033dbef40820646796a215483303081d9c08261bc92a5084578536d
4
+ data.tar.gz: 5484cb761e2c94362c34237612045071094008b7dcfe862c3d8e017a664fc75c
5
5
  SHA512:
6
- metadata.gz: fe20b127b0ccf7fa5cad36d40e417bc211bd14ae9a93b8128f2e912ffcadbcaac7950f006dd3dd56fd6d4d024f1bd7694809c181bfc84e361696248da3084ead
7
- data.tar.gz: bc9aca62d52e52f2d2be63a35e5acfc1edfca3aa63a6e904e1daecb27a8989ebcdb9b2e43fd45a25bc3a908c0923dc35fc15c0460d0255e86769ed037512f2a9
6
+ metadata.gz: 5fa91eaa85268edcdd25c096dc6da6368c53e372eb9c53cdd82900b1b99b8f23d4062dbb2cf089e9286bc926c4e0758ca377084c7d4253b4670856545703dedd
7
+ data.tar.gz: 7b460fcff8625c7418f7636a3e5b6883fd6f57aa7df8a7f9f313534c3747d6b1a4900fd74a60c467d3c8fa442cdf4a3305599feeae3e564d48137277d68e4d1c
@@ -3,22 +3,26 @@
3
3
  # Description: Parse and test data from a csv file.
4
4
  class CsvMigration
5
5
  # @param [String] file_name with extension (my_file.csv)
6
+ # @param [String] file_path path to file. By default current folder
6
7
  # @param [String] delimiter for parsing, by default = ';'
7
- def initialize(file_name:, delimiter: ';')
8
+ # @param [String] cli mode. If true then class will use only for command line. By default false
9
+ def initialize(file_name:, file_path: '', delimiter: ';', cli: false)
8
10
  # File name for parsing in csv format
9
11
  @file_name_csv = file_name
12
+ @file_path = file_path
10
13
  @delimiter = delimiter
14
+ @cli = cli
11
15
 
12
16
  @file_name = @file_name_csv.split('.csv').first
13
17
 
14
18
  # File for export correct data from the base file
15
- @correct_file_data_csv = File.expand_path("v_parser_correct_#{@file_name}.csv")
16
- @errors_log = File.expand_path("v_parser_errors_#{@file_name}.log")
17
- @duplicates_log = File.expand_path("v_parser_duplicates_#{@file_name}.log")
18
- @not_saved_file_data_errors = File.expand_path("v_parser_not_saved_#{@file_name}.log")
19
+ @correct_file_data_csv = File.expand_path("#{@file_path}v_parser_correct_#{@file_name}.csv")
20
+ @errors_log = File.expand_path("#{@file_path}v_parser_errors_#{@file_name}.log")
21
+ @duplicates_log = File.expand_path("#{@file_path}v_parser_duplicates_#{@file_name}.log")
22
+ @not_saved_file_data_errors = File.expand_path("#{@file_path}v_parser_not_saved_#{@file_name}.log")
19
23
 
20
24
  # Parsing file
21
- @file_for_parsing = File.expand_path(@file_name_csv)
25
+ @file_for_parsing = File.expand_path(@file_path + @file_name_csv)
22
26
 
23
27
  # Remove old files
24
28
  remove_old_files
@@ -155,6 +159,8 @@ class CsvMigration
155
159
 
156
160
  # Question action before saving data if exist errors
157
161
  def error_actions
162
+ return unless @cli
163
+
158
164
  print 'This file has errors. Do you want to save data without errors Y/n: '
159
165
  respond = STDIN.gets.chomp
160
166
 
@@ -201,8 +207,12 @@ class CsvMigration
201
207
  # @param [Object] value hash data from dict
202
208
  def check_field(data, key, value)
203
209
  if @parsing_file_header.find_index(key).nil?
204
- puts "Please, correct settings in the @ref_csv_head_from_file hash. Key #{key} has not been found in the header of #{@file_name_csv} file!"
205
- exit
210
+ if @cli
211
+ puts "Please, correct settings in the @ref_csv_head_from_file hash. Key #{key} has not been found in the header of #{@file_name_csv} file!"
212
+ exit
213
+ else
214
+ raise ArgumentError, "Please, correct settings in the @ref_csv_head_from_file hash. Key #{key} has not been found in the header of #{@file_name_csv} file!"
215
+ end
206
216
  end
207
217
 
208
218
  if value[:require] && blank?(data[@parsing_file_header.find_index(key)])
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: csv_migration
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
- - Danilevsky Kirill (Syndicode.com)
7
+ - Danilevsky Kirill
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-10 00:00:00.000000000 Z
11
+ date: 2021-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -51,7 +51,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
51
51
  - !ruby/object:Gem::Version
52
52
  version: '0'
53
53
  requirements: []
54
- rubygems_version: 3.0.3
54
+ rubygems_version: 3.1.2
55
55
  signing_key:
56
56
  specification_version: 4
57
57
  summary: Migration system from a csv file