csv2hash 0.4.0 → 0.5.0

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
  SHA1:
3
- metadata.gz: 388884c9854027a36c9f704d77f8cd31d2fe8aba
4
- data.tar.gz: ffb86ac1d924c8cb6041aec965c42edf19b1226d
3
+ metadata.gz: 043c4be4542235e09772f8ca2249288158f7230f
4
+ data.tar.gz: 2eb0e8d2a0e13854f103b21b34d4a54fbb55e64f
5
5
  SHA512:
6
- metadata.gz: fa1f10d91cb064ae715673074dc4bfd8e095c79cee29efa8cee1db95556a2ac909bd7f3337024c8121f5972fe87d9911a3a921566195859862b5d0f4c832880b
7
- data.tar.gz: 710c7f822206b531de694f316ab2f2a5d0c76afe83a0d44f92816054f519b20e9fd32d70b5da0865481c6770f0f2319519e52203c5fc8d0ada551abd565ebf15
6
+ metadata.gz: 43c070b76ca768925631f70c3e95750b5ec7edf9438e856ee58160c288f04a9c6d2215bc04c01af7a464ef80a991c1adb88797b5f4183d7c53922b1d09ca893b
7
+ data.tar.gz: 62050c84397a144b712a592cc9e39d28d1bec6965fdbe31d35263016cf31a4b4a35b2450538088da239583ed76a0d9ce7e8ec0c3e129176792ed39e5a6c06715
data/Gemfile.lock CHANGED
@@ -1,11 +1,18 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- csv2hash (0.4.0)
4
+ csv2hash (0.5.0)
5
+ activesupport (~> 4.1)
5
6
 
6
7
  GEM
7
8
  remote: http://rubygems.org/
8
9
  specs:
10
+ activesupport (4.1.4)
11
+ i18n (~> 0.6, >= 0.6.9)
12
+ json (~> 1.7, >= 1.7.7)
13
+ minitest (~> 5.1)
14
+ thread_safe (~> 0.1)
15
+ tzinfo (~> 1.1)
9
16
  coderay (1.1.0)
10
17
  coveralls (0.7.1)
11
18
  multi_json (~> 1.3)
@@ -15,10 +22,13 @@ GEM
15
22
  thor
16
23
  diff-lcs (1.2.5)
17
24
  docile (1.1.5)
25
+ i18n (0.6.11)
18
26
  its (0.2.0)
19
27
  rspec-core
28
+ json (1.8.1)
20
29
  method_source (0.8.2)
21
30
  mime-types (2.3)
31
+ minitest (5.4.0)
22
32
  multi_json (1.10.1)
23
33
  netrc (0.7.7)
24
34
  pry (0.10.0)
@@ -50,16 +60,19 @@ GEM
50
60
  term-ansicolor (1.3.0)
51
61
  tins (~> 1.0)
52
62
  thor (0.19.1)
63
+ thread_safe (0.3.4)
53
64
  tins (1.3.2)
65
+ tzinfo (1.2.1)
66
+ thread_safe (~> 0.1)
54
67
 
55
68
  PLATFORMS
56
69
  ruby
57
70
 
58
71
  DEPENDENCIES
59
- bundler (~> 1.3)
72
+ bundler (~> 1.6)
60
73
  coveralls
61
74
  csv2hash!
62
- its
75
+ its (~> 0.2)
63
76
  pry
64
- rake
65
- rspec
77
+ rake (~> 10.3)
78
+ rspec (~> 3.0)
data/README.md CHANGED
@@ -227,7 +227,7 @@ You can define the number of rows to skip in the header of the CSV.
227
227
  Pasrer can take several parameters like that:
228
228
 
229
229
  ```
230
- definition, file_path_or_data, ignore_blank_line=false
230
+ definition, file_path_or_data, ignore_blank_line: false
231
231
  ```
232
232
 
233
233
  in file_path_or_data attribute you can pass directly an Array of data (Array with 2 dimensions) really useful for testing, if you don't care about blank lines in your CSV you can ignore them.
@@ -266,7 +266,7 @@ You need call `.parse()` return `data_wrapper` if `.parse()` is invalid, you can
266
266
  in your code
267
267
 
268
268
  ```
269
- parser = Csv2hash::Main.new(definition, file_path_or_data, ignore_blank_line=false).new
269
+ parser = Csv2hash::Main.new(definition, file_path_or_data, ignore_blank_line: false).new
270
270
  response = parser.parse
271
271
  return response if response.valid?
272
272
  # Whatever
@@ -352,11 +352,28 @@ Csv data
352
352
  ```
353
353
  [ [ 'Foo' ] ]
354
354
  ```
355
+
356
+ # Upgrading from 0.4 to 0.5
357
+
358
+ Signature of ```Csv2hash::Main#new``` has changed too
359
+
360
+ Prior to 0.5 :
361
+
362
+ ```
363
+ Csv2Hash::Main.new(definition, file_path_or_data, ignore_blank_line=false)
364
+ ```
365
+
366
+ Starting from 0.5 :
367
+
368
+ ```
369
+ Csv2Hash::Main.new(definition, file_path_or_data, ignore_blank_line: false)
370
+ ```
371
+
355
372
  # Upgrading from 0.3 to 0.4
356
373
 
357
374
  Signature of ```Csv2hash::Main#new``` has changed too
358
375
 
359
- Prior to 0.3 :
376
+ Prior to 0.4 :
360
377
 
361
378
  ```
362
379
  Csv2Hash::Main.new(definition, file_path_or_data, break_on_failure=true, ignore_blank_line=false)
@@ -364,7 +381,7 @@ Prior to 0.3 :
364
381
 
365
382
  call ```.parse!``` for same result
366
383
 
367
- Starting from 0.3 :
384
+ Starting from 0.4 :
368
385
 
369
386
  ```
370
387
  Csv2Hash::Main.new(definition, file_path_or_data, ignore_blank_line=false)
data/ReleaseNotes.md CHANGED
@@ -1,3 +1,11 @@
1
+ ### VERSION 0.5.0
2
+
3
+ * backwards incompatible changes
4
+ * The signature of Csv2hash::Main#new has changed.
5
+
6
+ * refactoring
7
+ * remove params ``` ignore_blank_line ``` to benefit of options of Hash
8
+
1
9
  ### VERSION 0.4.0
2
10
 
3
11
  * backwards incompatible changes
data/csv2hash.gemspec CHANGED
@@ -17,9 +17,12 @@ Gem::Specification.new do |spec|
17
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
18
  spec.require_paths = ['lib']
19
19
 
20
- spec.add_development_dependency 'bundler', '~> 1.3'
21
- spec.add_development_dependency 'rake'
22
- spec.add_development_dependency 'rspec'
23
- spec.add_development_dependency 'its'
20
+ spec.add_dependency 'activesupport', '~> 4.1'
21
+
22
+ spec.add_development_dependency 'bundler', '~> 1.6'
23
+ spec.add_development_dependency 'rake', '~> 10.3'
24
+ spec.add_development_dependency 'rspec', '~> 3.0'
25
+ spec.add_development_dependency 'its', '~> 0.2'
26
+
24
27
  spec.required_ruby_version = '~> 2.1'
25
28
  end
@@ -6,7 +6,7 @@ module Csv2hash::Parser::Collection
6
6
  data_computed[:data] ||= []
7
7
  self.data_source.each_with_index do |line, y|
8
8
  next if y < definition.header_size
9
- next if self.ignore_blank_line and line.compact.empty?
9
+ next if self.options.fetch(:ignore_blank_line) and line.compact.empty?
10
10
  data_computed[:data] << {}.tap do |data_parsed|
11
11
  fill_it data_parsed, line
12
12
  end
@@ -4,7 +4,7 @@ module Csv2hash::Validator::Collection
4
4
  def validate_data!
5
5
  self.data_source.each_with_index do |line, y|
6
6
  next if y < definition.header_size
7
- next if self.ignore_blank_line and line.compact.empty?
7
+ next if self.options.fetch(:ignore_blank_line) and line.compact.empty?
8
8
  validate_rules y
9
9
  end
10
10
  end
@@ -1,3 +1,3 @@
1
1
  module Csv2hash
2
- VERSION = '0.4.0'
2
+ VERSION = '0.5.0'
3
3
  end
data/lib/csv2hash.rb CHANGED
@@ -15,6 +15,8 @@ require_relative 'csv2hash/notifier'
15
15
  require_relative 'csv2hash/extra_validator'
16
16
  require_relative 'csv2hash/adapters/base'
17
17
 
18
+ require 'active_support/core_ext/array/extract_options'
19
+
18
20
  begin
19
21
  require 'pry'
20
22
  rescue LoadError
@@ -24,16 +26,18 @@ module Csv2hash
24
26
  class Main
25
27
  include Csv2hash::StructureValidator
26
28
 
27
- attr_accessor :definition, :file_path_or_data, :data, :notifier, :break_on_failure, :errors, :ignore_blank_line
29
+ attr_accessor :definition, :file_path_or_data, :data, :notifier, :break_on_failure, :errors, :options
28
30
 
29
- def initialize definition, file_path_or_data, ignore_blank_line=false
31
+ def initialize definition, file_path_or_data, *args
32
+ self.options = args.extract_options!
30
33
  self.definition, self.file_path_or_data = definition, file_path_or_data
31
- @data_source = data_source
32
- dynamic_lib_loading 'Parser'
33
34
  self.break_on_failure, self.errors = false, []
34
- dynamic_lib_loading 'Validator'
35
35
  self.notifier = Notifier.new
36
- self.ignore_blank_line = ignore_blank_line
36
+
37
+ dynamic_lib_loading 'Parser'
38
+ dynamic_lib_loading 'Validator'
39
+
40
+ @data_source = data_source
37
41
 
38
42
  init_plugins
39
43
  end
@@ -7,9 +7,10 @@ describe Csv2hash::Parser::Collection do
7
7
  end
8
8
 
9
9
  let(:data_source) { [ [ 'John Doe' ], [ 'Jane Doe' ] ] }
10
+ let(:ignore_blank_line) { false }
10
11
 
11
12
  subject do
12
- Csv2hash::Main.new(definition, data_source, ignore_blank_line=false)
13
+ Csv2hash::Main.new(definition, data_source, ignore_blank_line: ignore_blank_line)
13
14
  end
14
15
 
15
16
  context 'regular way' do
@@ -47,9 +48,9 @@ describe Csv2hash::Parser::Collection do
47
48
 
48
49
  context '#ignore_blank_line' do
49
50
  let(:data_source) { [ [ 'John Doe' ], [ 'Jane Doe' ], [ nil ] ] }
51
+ let(:ignore_blank_line) { true }
50
52
  it {
51
53
  expect(subject.tap do |parser|
52
- parser.ignore_blank_line = true
53
54
  parser.parse
54
55
  end.data).to eql({ data: [ { 'name' => 'John Doe' }, { 'name' => 'Jane Doe' } ] })
55
56
  }
@@ -9,7 +9,7 @@ describe Csv2hash::Parser::Mapping do
9
9
  let(:data_source) { [ [ 'John Doe' ] ] }
10
10
 
11
11
  subject do
12
- Csv2hash::Main.new(definition, data_source, ignore_blank_line=false)
12
+ Csv2hash::Main.new(definition, data_source, ignore_blank_line: false)
13
13
  end
14
14
 
15
15
  context 'regular way' do
@@ -12,7 +12,7 @@ describe Csv2hash::StructureValidator do
12
12
  end
13
13
 
14
14
  subject do
15
- Csv2hash::Main.new(definition, data_source, ignore_blank_line=false)
15
+ Csv2hash::Main.new(definition, data_source, ignore_blank_line: false)
16
16
  end
17
17
 
18
18
  context 'the csv with errors' do
@@ -8,9 +8,10 @@ describe Csv2hash::Validator::Collection do
8
8
  definition.default!
9
9
  end
10
10
  end
11
+ let(:ignore_blank_line) { false }
11
12
 
12
13
  subject do
13
- Csv2hash::Main.new(definition, data_source, ignore_blank_line=false)
14
+ Csv2hash::Main.new(definition, data_source, ignore_blank_line: ignore_blank_line)
14
15
  end
15
16
 
16
17
  before do
@@ -30,7 +31,7 @@ describe Csv2hash::Validator::Collection do
30
31
 
31
32
  context '#ignore_blank_line' do
32
33
  let(:data_source) { [ [ ] ] }
33
- before { subject.ignore_blank_line = true }
34
+ let(:ignore_blank_line) { true }
34
35
  it { expect { subject.validate_data! }.to_not raise_error }
35
36
  context 'csv mode' do
36
37
  before { subject.break_on_failure = false }
@@ -50,7 +51,7 @@ describe Csv2hash::Validator::Collection do
50
51
 
51
52
  context 'wihtout exception' do
52
53
  let(:data_source) { [ [ ] ]}
53
-
54
+
54
55
  before do
55
56
  allow(subject).to receive(:break_on_failure) { false }
56
57
  end
@@ -10,7 +10,7 @@ describe Csv2hash::Validator::Mapping do
10
10
  end
11
11
 
12
12
  subject do
13
- Csv2hash::Main.new(definition, data_source, ignore_blank_line=false)
13
+ Csv2hash::Main.new(definition, data_source, ignore_blank_line: false)
14
14
  end
15
15
 
16
16
  before do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: csv2hash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joel AZEMAR
@@ -10,62 +10,76 @@ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2013-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.1'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
31
  - - "~>"
18
32
  - !ruby/object:Gem::Version
19
- version: '1.3'
33
+ version: '1.6'
20
34
  type: :development
21
35
  prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
24
38
  - - "~>"
25
39
  - !ruby/object:Gem::Version
26
- version: '1.3'
40
+ version: '1.6'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rake
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
- - - ">="
45
+ - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: '0'
47
+ version: '10.3'
34
48
  type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
- - - ">="
52
+ - - "~>"
39
53
  - !ruby/object:Gem::Version
40
- version: '0'
54
+ version: '10.3'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rspec
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
- - - ">="
59
+ - - "~>"
46
60
  - !ruby/object:Gem::Version
47
- version: '0'
61
+ version: '3.0'
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
- - - ">="
66
+ - - "~>"
53
67
  - !ruby/object:Gem::Version
54
- version: '0'
68
+ version: '3.0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: its
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
- - - ">="
73
+ - - "~>"
60
74
  - !ruby/object:Gem::Version
61
- version: '0'
75
+ version: '0.2'
62
76
  type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
- - - ">="
80
+ - - "~>"
67
81
  - !ruby/object:Gem::Version
68
- version: '0'
82
+ version: '0.2'
69
83
  description: DSL to map a CSV to a Ruby Hash
70
84
  email: joel.azemar@gmail.com
71
85
  executables: