csv-importer 0.3.0 → 0.3.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 07b837a8650d40afb4feb4be4b9d1679d4f7a41a
4
- data.tar.gz: f74a63d0b1c65c647ca8ccd102151a2c542f1212
3
+ metadata.gz: 9fb2af22af454df8a5d98c1d4fb2b8045c75c39b
4
+ data.tar.gz: 0ea722d76a33fc31fe3cea489d95e480b63b188c
5
5
  SHA512:
6
- metadata.gz: 0b3453bf9dc18bc3dcd66b04b7901c5e68d9c66afa362d4e0ae9965dc82745a9380dd53e8d5fbdcc42cc7ab4b3501f3d1debfe2894e013b9fa08a7dc90012dcb
7
- data.tar.gz: 633f1f1e78cb60a1dd911349ab5651d498acfb0a1ff8983f88e144a4d429de17a43d3e2bd43e12538a1a31c15edf327ccca290c908f727f06811253dc8aaf8d5
6
+ metadata.gz: 7afd22eabb1c1d6e9aa04aac774f0063e8682e5a58a1c5d3fe339084f47fa8f432c82f80e4f78b5cb37bedc6d82ae4f6d9ddac8c044209510c40053182d45d37
7
+ data.tar.gz: d52f0d10d2b8916e2f049c69301539fc42e09ef3610955cb1eed8ebf8e398080eab4a7b654d6cf0a19dd51447ea23dc2268ec01c2b209adcc16a0f580b8d55a5
@@ -1,6 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2.2
3
+ - 2.3.0
4
4
  addons:
5
5
  code_climate:
6
6
  repo_token: 0e005c563813539e6d0cdca9a3e95b3c0f1c79f32284f8eaa93b54c57303d427
@@ -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
- [@shvetsovdm]: https://github.com/shvetsovdm
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('UTF-8'), {invalid: :replace, undef: :replace, replace: ''}) # Remove invalid byte sequences
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
 
@@ -1,3 +1,3 @@
1
1
  module CSVImporter
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
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.3.0
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-02-05 00:00:00.000000000 Z
11
+ date: 2016-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: virtus