csv-importer 0.7.0 → 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5e17c85aa62e6f2774f1cb86dcea9d7743622b73690fb896228d1bf7ce54951e
4
- data.tar.gz: acfd22bf68c1c228a0afecba046cf3cb7231311192ee1ee5c88828a56a51f429
3
+ metadata.gz: 48a0833adc98a3eb391c5f8f5dfcbf17e18d2b2b67c30ac6ce61ac10c75f4e65
4
+ data.tar.gz: 35af734114d7edc62208492860340747696ede74b26c37af8f69abb8cb3664db
5
5
  SHA512:
6
- metadata.gz: c5c8894e68eaa33418761a9cad3ab8f0ddfea0eeaa3e62101ab1105a40978b7c206dc7448a4b536f9efc06c06b952935146efe9b4ae010c9a3f98428f649b641
7
- data.tar.gz: 66f498dc9d2e62bf413ba35ac362b03fa557640c724cafb8cc38686bfe825334455d936c1c8a4e79b97fc4ec0355887cb0f6dee178b0f3893d0b37c6dc043b09
6
+ metadata.gz: e39e5ae5ba02cd31d77972f452fded7fc7584bacac159a6e0a9bd305bb8f3e597b843af2006ce7e64e29de7b70fec7015ca485bdfe0f562ae8727150a682f4bb
7
+ data.tar.gz: bce7c77c6d159788228bfbc6da9920bbbf810344d1075113e57edce647288da907a0d7c8358710b1729be5463d85492a5ce63be1299eaf519e0fb8a04c691a6b
data/.travis.yml CHANGED
@@ -1,6 +1,7 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 2.3.0
4
+ - 2.7
4
5
  addons:
5
6
  code_climate:
6
7
  repo_token: bcecbf1b229a2ddd666a2c3830f26a0113fd56ae1586d30d2d3fb1af837bf0e4
data/CHANGELOG.md CHANGED
@@ -2,6 +2,22 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ ## [0.8.2] - 2022-08-02
6
+
7
+ ### Fixed
8
+
9
+ * Handle Invisible Chars in headers. [#107][] by [@tracyloisel][]
10
+
11
+ ## [0.8.1] - 2021-02-21
12
+
13
+ * Rails 6.2 compability. [#99][] by [@stevenou][]
14
+
15
+ ## [0.8.0] - 2020-09-02
16
+
17
+ ### Fixed
18
+
19
+ * Ruby 2.7 compatibility. [#93][] by [@perezperret][]
20
+
5
21
  ## [0.7.0] - 2019-11-29
6
22
 
7
23
  ### Added
@@ -195,6 +211,9 @@ report object instead of raising an exception.
195
211
  [#83]: https://github.com/pcreux/csv-importer/issues/83
196
212
  [#85]: https://github.com/pcreux/csv-importer/issues/85
197
213
  [#88]: https://github.com/pcreux/csv-importer/issues/88
214
+ [#93]: https://github.com/pcreux/csv-importer/issues/93
215
+ [#99]: https://github.com/pcreux/csv-importer/issues/99
216
+ [#107]: https://github.com/pcreux/csv-importer/issues/107
198
217
  [@brain-geek]: https://github.com/brain-geek
199
218
  [@danielweinmann]: https://github.com/danielweinmann
200
219
  [@egg-chicken]: https://github.com/egg-chicken
@@ -203,6 +222,9 @@ report object instead of raising an exception.
203
222
  [@mltsy]: https://github.com/mltsy
204
223
  [@paulodeleo]: https://github.com/paulodeleo
205
224
  [@pcreux]: https://github.com/pcreux
225
+ [@perezperret]: https://github.com/perezperret
206
226
  [@pnomolos]: https://github.com/pnomolos
207
227
  [@shvetsovdm]: https://github.com/shvetsovdm
208
- [@stas]: https://github.com/stas
228
+ [@stas]: https://github.com/stas
229
+ [@stevenou]: https://github.com/stevenou
230
+ [@tracyloisel]: https://github.com/tracyloisel
data/Gemfile CHANGED
@@ -2,9 +2,3 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in csv-importer.gemspec
4
4
  gemspec
5
-
6
- gem 'rspec', '~> 3.3.0'
7
- gem 'guard-rspec'
8
- gem 'activemodel'
9
- gem 'simplecov', require: nil
10
- gem "codeclimate-test-reporter", require: nil
data/csv-importer.gemspec CHANGED
@@ -20,6 +20,10 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_dependency "virtus"
22
22
 
23
- spec.add_development_dependency "bundler", "~> 1.8"
24
- spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.3.0"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "guard-rspec"
26
+ spec.add_development_dependency "activemodel", "~> 5"
27
+ spec.add_development_dependency "simplecov"
28
+ spec.add_development_dependency "codeclimate-test-reporter"
25
29
  end
@@ -14,8 +14,12 @@ module CSVImporter
14
14
  @csv_rows ||= begin
15
15
  sane_content = sanitize_content(read_content)
16
16
  separator = detect_separator(sane_content)
17
- cells = CSV.parse(sane_content, col_sep: separator, quote_char: quote_char, skip_blanks: true, encoding: encoding)
18
- sanitize_cells(cells)
17
+ cells = CSV.parse(
18
+ sane_content,
19
+ col_sep: separator, quote_char: quote_char, skip_blanks: true,
20
+ external_encoding: source_encoding
21
+ )
22
+ sanitize_cells(encode_cells(cells))
19
23
  end
20
24
  end
21
25
 
@@ -44,9 +48,8 @@ module CSVImporter
44
48
  end
45
49
 
46
50
  def sanitize_content(csv_content)
47
- internal_encoding = encoding.split(':').last
48
51
  csv_content
49
- .encode(Encoding.find(internal_encoding), {invalid: :replace, undef: :replace, replace: ''}) # Remove invalid byte sequences
52
+ .encode(Encoding.find(source_encoding), invalid: :replace, undef: :replace, replace: '') # Remove invalid byte sequences
50
53
  .gsub(/\r\r?\n?/, "\n") # Replaces windows line separators with "\n"
51
54
  end
52
55
 
@@ -75,5 +78,21 @@ module CSVImporter
75
78
  end
76
79
  end
77
80
  end
81
+
82
+ def encode_cells(rows)
83
+ rows.map do |cells|
84
+ cells.map do |cell|
85
+ cell ? cell.encode(target_encoding) : ""
86
+ end
87
+ end
88
+ end
89
+
90
+ def source_encoding
91
+ encoding.split(':').first || 'UTF-8'
92
+ end
93
+
94
+ def target_encoding
95
+ encoding.split(':').last || 'UTF-8'
96
+ end
78
97
  end
79
98
  end
@@ -9,6 +9,9 @@ module CSVImporter
9
9
 
10
10
  def columns
11
11
  column_names.map do |column_name|
12
+ # ensure column name escapes invisible characters
13
+ column_name = column_name.gsub(/[^[:print:]]/, '')
14
+
12
15
  Column.new(
13
16
  name: column_name,
14
17
  definition: find_column_definition(column_name)
@@ -77,11 +77,11 @@ module CSVImporter
77
77
  # Error from the model mapped back to the CSV header if we can
78
78
  def errors
79
79
  Hash[
80
- model.errors.map do |attribute, errors|
80
+ model.errors.to_hash.map do |attribute, errors|
81
81
  if column_name = header.column_name_for_model_attribute(attribute)
82
- [column_name, errors]
82
+ [column_name, errors.last]
83
83
  else
84
- [attribute, errors]
84
+ [attribute, errors.last]
85
85
  end
86
86
  end
87
87
  ]
@@ -1,3 +1,3 @@
1
1
  module CSVImporter
2
- VERSION = "0.7.0"
2
+ VERSION = "0.8.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: csv-importer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Philippe Creux
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-29 00:00:00.000000000 Z
11
+ date: 2022-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: virtus
@@ -25,34 +25,90 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: bundler
28
+ name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.8'
33
+ version: 3.3.0
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.8'
40
+ version: 3.3.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard-rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: activemodel
43
71
  requirement: !ruby/object:Gem::Requirement
44
72
  requirements:
45
73
  - - "~>"
46
74
  - !ruby/object:Gem::Version
47
- version: '10.0'
75
+ version: '5'
48
76
  type: :development
49
77
  prerelease: false
50
78
  version_requirements: !ruby/object:Gem::Requirement
51
79
  requirements:
52
80
  - - "~>"
53
81
  - !ruby/object:Gem::Version
54
- version: '10.0'
55
- description:
82
+ version: '5'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: codeclimate-test-reporter
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description:
56
112
  email:
57
113
  - pcreux@gmail.com
58
114
  executables: []
@@ -89,7 +145,7 @@ homepage: https://github.com/pcreux/csv-importer
89
145
  licenses:
90
146
  - MIT
91
147
  metadata: {}
92
- post_install_message:
148
+ post_install_message:
93
149
  rdoc_options: []
94
150
  require_paths:
95
151
  - lib
@@ -104,8 +160,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
160
  - !ruby/object:Gem::Version
105
161
  version: '0'
106
162
  requirements: []
107
- rubygems_version: 3.0.3
108
- signing_key:
163
+ rubygems_version: 3.1.6
164
+ signing_key:
109
165
  specification_version: 4
110
166
  summary: CSV Import for humans
111
167
  test_files: []