csv-importer 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/CHANGELOG.md +10 -1
- data/README.md +9 -1
- data/lib/csv_importer/csv_reader.rb +4 -2
- data/lib/csv_importer/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9fb2af22af454df8a5d98c1d4fb2b8045c75c39b
|
4
|
+
data.tar.gz: 0ea722d76a33fc31fe3cea489d95e480b63b188c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7afd22eabb1c1d6e9aa04aac774f0063e8682e5a58a1c5d3fe339084f47fa8f432c82f80e4f78b5cb37bedc6d82ae4f6d9ddac8c044209510c40053182d45d37
|
7
|
+
data.tar.gz: d52f0d10d2b8916e2f049c69301539fc42e09ef3610955cb1eed8ebf8e398080eab4a7b654d6cf0a19dd51447ea23dc2268ec01c2b209adcc16a0f580b8d55a5
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,13 @@
|
|
2
2
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
|
5
|
+
## [0.3.1] - 2016-05-09
|
6
|
+
|
7
|
+
### Added
|
8
|
+
|
9
|
+
* You can customize the encoding with the `encoding` option. Default is
|
10
|
+
`UTF-8`. ([#38][] by [@egg-chicken][])
|
11
|
+
|
5
12
|
## [0.3.0] - 2016-02-05
|
6
13
|
|
7
14
|
### Added
|
@@ -97,4 +104,6 @@ report object instead of raising an exception.
|
|
97
104
|
|
98
105
|
<!--- The following link definition list is generated by PimpMyChangelog --->
|
99
106
|
[#26]: https://github.com/BrewhouseTeam/csv-importer/issues/26
|
100
|
-
[
|
107
|
+
[#38]: https://github.com/BrewhouseTeam/csv-importer/issues/38
|
108
|
+
[@egg-chicken]: https://github.com/egg-chicken
|
109
|
+
[@shvetsovdm]: https://github.com/shvetsovdm
|
data/README.md
CHANGED
@@ -244,7 +244,7 @@ end
|
|
244
244
|
import = ImportUserCSV.new(content: "email\nbob@example.com\nINVALID_EMAIL")
|
245
245
|
import.valid_header? # => true
|
246
246
|
import.run!
|
247
|
-
import.success? # => false
|
247
|
+
import.report.success? # => false
|
248
248
|
import.report.status # => :aborted
|
249
249
|
import.report.message # => "Import aborted"
|
250
250
|
```
|
@@ -399,6 +399,14 @@ import.run!
|
|
399
399
|
# => [ ["bob@example.com", "bob \"elvis\" wilson"] ]
|
400
400
|
```
|
401
401
|
|
402
|
+
### Custom encoding
|
403
|
+
|
404
|
+
You can handle exotic encodings with the `encoding` option.
|
405
|
+
|
406
|
+
```ruby
|
407
|
+
ImportUserCSV.new(content: "メール,氏名".encode('SJIS'), encoding: 'SJIS:UTF-8')
|
408
|
+
```
|
409
|
+
|
402
410
|
## Development
|
403
411
|
|
404
412
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -8,12 +8,13 @@ module CSVImporter
|
|
8
8
|
attribute :file # IO
|
9
9
|
attribute :path, String
|
10
10
|
attribute :quote_char, String, default: '"'
|
11
|
+
attribute :encoding, String, default: 'UTF-8:UTF-8'
|
11
12
|
|
12
13
|
def csv_rows
|
13
14
|
@csv_rows ||= begin
|
14
15
|
sane_content = sanitize_content(read_content)
|
15
16
|
separator = detect_separator(sane_content)
|
16
|
-
cells = CSV.parse(sane_content, col_sep: separator, quote_char: quote_char, skip_blanks: true)
|
17
|
+
cells = CSV.parse(sane_content, col_sep: separator, quote_char: quote_char, skip_blanks: true, encoding: encoding)
|
17
18
|
sanitize_cells(cells)
|
18
19
|
end
|
19
20
|
end
|
@@ -43,8 +44,9 @@ module CSVImporter
|
|
43
44
|
end
|
44
45
|
|
45
46
|
def sanitize_content(csv_content)
|
47
|
+
internal_encoding = encoding.split(':').last
|
46
48
|
csv_content
|
47
|
-
.encode(Encoding.find(
|
49
|
+
.encode(Encoding.find(internal_encoding), {invalid: :replace, undef: :replace, replace: ''}) # Remove invalid byte sequences
|
48
50
|
.gsub(/\r\r?\n?/, "\n") # Replaces windows line separators with "\n"
|
49
51
|
end
|
50
52
|
|
data/lib/csv_importer/version.rb
CHANGED
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.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Philippe Creux
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-05-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: virtus
|