csv2hash 0.7.3 → 0.7.5

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: 47f29eda9ebb4f6b019424849700862ea05ec24a
4
- data.tar.gz: 52e81b5c37ae18cb65922444637033feab9e470c
3
+ metadata.gz: 98a1f20cad762675329d3eeb1a4c916200dd3b66
4
+ data.tar.gz: e4f8835e3204827e081fe07a99ad5c98bfdc6e93
5
5
  SHA512:
6
- metadata.gz: 8353d11495c3b9f3a0d1f5e1daf90604459123f982adadff9022ce63255d21519a17b6b9abb1453cba7f68d007c5a990f970eda0b58c6cc05e7562f4a169c857
7
- data.tar.gz: ed96cc24f8ea73e0f862a97a888509235fec77998005f52c500648ec75e6a820367533b2401d1ba43a7f693fdffb8cbf7b9acc07b15cdc31c7855a66b0236092
6
+ metadata.gz: ba40bdb3783b76f10791df8e6de5f20461097ef966b4e4eb7a73dab030b6265e32125e0ed502de97080dd8be98f4714e214d7717f463b411f7730b92dc03b9a0
7
+ data.tar.gz: 7c9b7c83c2982fa6fbd73ba8d4e56f6386f7b23ffb1216a90e9fae64c6947a38ba2cc3639c303023b938f5b019623c89c58bd680560d048937b7598eb6549459
data/CHANGELOG.md CHANGED
@@ -1,3 +1,18 @@
1
+ ### VERSION 0.7.5
2
+
3
+ Add extra feature on Autodiscover Regex field.
4
+
5
+ * enhancements
6
+ * Add case sensitive option on auto discover field
7
+ * Add exact matching option on auto discover field
8
+
9
+ * [fullchanges](https://github.com/FinalCAD/csv2hash/pull/25)
10
+ * [Author Joel AZEMAR](https://github.com/joel)
11
+
12
+ ### VERSION 0.7.4
13
+
14
+ * security updates
15
+
1
16
  ### VERSION 0.7.3
2
17
 
3
18
  * enhancements
data/Gemfile.lock CHANGED
@@ -1,22 +1,22 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- csv2hash (0.7.3)
4
+ csv2hash (0.7.5)
5
5
  activesupport (~> 4.1)
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
9
9
  specs:
10
- actionpack (4.1.6)
11
- actionview (= 4.1.6)
12
- activesupport (= 4.1.6)
10
+ actionpack (4.1.8)
11
+ actionview (= 4.1.8)
12
+ activesupport (= 4.1.8)
13
13
  rack (~> 1.5.2)
14
14
  rack-test (~> 0.6.2)
15
- actionview (4.1.6)
16
- activesupport (= 4.1.6)
15
+ actionview (4.1.8)
16
+ activesupport (= 4.1.8)
17
17
  builder (~> 3.1)
18
18
  erubis (~> 2.7.0)
19
- activesupport (4.1.6)
19
+ activesupport (4.1.8)
20
20
  i18n (~> 0.6, >= 0.6.9)
21
21
  json (~> 1.7, >= 1.7.7)
22
22
  minitest (~> 5.1)
@@ -24,12 +24,12 @@ GEM
24
24
  tzinfo (~> 1.1)
25
25
  builder (3.2.2)
26
26
  coderay (1.1.0)
27
- coveralls (0.7.1)
27
+ coveralls (0.7.2)
28
28
  multi_json (~> 1.3)
29
- rest-client
29
+ rest-client (= 1.6.7)
30
30
  simplecov (>= 0.7)
31
- term-ansicolor
32
- thor
31
+ term-ansicolor (= 1.2.2)
32
+ thor (= 0.18.1)
33
33
  diff-lcs (1.2.5)
34
34
  docile (1.1.5)
35
35
  erubis (2.7.0)
@@ -37,19 +37,18 @@ GEM
37
37
  activesupport (>= 3.0.0)
38
38
  railties (>= 3.0.0)
39
39
  i18n (0.6.11)
40
- inch (0.4.10)
40
+ inch (0.5.7)
41
41
  pry
42
42
  sparkr (>= 0.2.0)
43
43
  term-ansicolor
44
- yard (~> 0.8.7)
44
+ yard (~> 0.8.7.5)
45
45
  its (0.2.0)
46
46
  rspec-core
47
47
  json (1.8.1)
48
48
  method_source (0.8.2)
49
- mime-types (2.3)
50
- minitest (5.4.2)
49
+ mime-types (2.4.3)
50
+ minitest (5.4.3)
51
51
  multi_json (1.10.1)
52
- netrc (0.7.7)
53
52
  pry (0.10.1)
54
53
  coderay (~> 1.1.0)
55
54
  method_source (~> 0.8.1)
@@ -57,43 +56,42 @@ GEM
57
56
  rack (1.5.2)
58
57
  rack-test (0.6.2)
59
58
  rack (>= 1.0)
60
- railties (4.1.6)
61
- actionpack (= 4.1.6)
62
- activesupport (= 4.1.6)
59
+ railties (4.1.8)
60
+ actionpack (= 4.1.8)
61
+ activesupport (= 4.1.8)
63
62
  rake (>= 0.8.7)
64
63
  thor (>= 0.18.1, < 2.0)
65
- rake (10.3.2)
66
- rest-client (1.7.2)
67
- mime-types (>= 1.16, < 3.0)
68
- netrc (~> 0.7)
64
+ rake (10.4.0)
65
+ rest-client (1.6.7)
66
+ mime-types (>= 1.16)
69
67
  rspec (3.1.0)
70
68
  rspec-core (~> 3.1.0)
71
69
  rspec-expectations (~> 3.1.0)
72
70
  rspec-mocks (~> 3.1.0)
73
- rspec-core (3.1.3)
71
+ rspec-core (3.1.7)
74
72
  rspec-support (~> 3.1.0)
75
- rspec-expectations (3.1.1)
73
+ rspec-expectations (3.1.2)
76
74
  diff-lcs (>= 1.2.0, < 2.0)
77
75
  rspec-support (~> 3.1.0)
78
- rspec-mocks (3.1.0)
76
+ rspec-mocks (3.1.3)
79
77
  rspec-support (~> 3.1.0)
80
- rspec-support (3.1.0)
81
- simplecov (0.9.0)
78
+ rspec-support (3.1.2)
79
+ simplecov (0.9.1)
82
80
  docile (~> 1.1.0)
83
- multi_json
81
+ multi_json (~> 1.0)
84
82
  simplecov-html (~> 0.8.0)
85
83
  simplecov-html (0.8.0)
86
84
  slop (3.6.0)
87
85
  sparkr (0.4.1)
88
- term-ansicolor (1.3.0)
89
- tins (~> 1.0)
90
- thor (0.19.1)
86
+ term-ansicolor (1.2.2)
87
+ tins (~> 0.8)
88
+ thor (0.18.1)
91
89
  thread_safe (0.3.4)
92
- tins (1.3.2)
90
+ tins (0.13.2)
93
91
  tomparse (0.4.2)
94
92
  tzinfo (1.2.2)
95
93
  thread_safe (~> 0.1)
96
- yard (0.8.7.4)
94
+ yard (0.8.7.6)
97
95
  yard-tomdoc (0.7.1)
98
96
  tomparse (>= 0.4.0)
99
97
  yard
data/README.md CHANGED
@@ -23,8 +23,9 @@ It is a DSL to validate and map a CSV to a Ruby Hash.
23
23
  * [Definition DSL](#definition-dsl)
24
24
  * [Definition Rules](#definition-rules)
25
25
  * [Default rules values](#default-rules-values)
26
- * [define where your data are expected](#define-where-your-data-are-expected)
26
+ * [Define where your data are expected](#define-where-your-data-are-expected)
27
27
  * [Samples](#samples)
28
+ * [Autodiscover generale setting](#autodiscover-generale-setting)
28
29
  * [[MAPPING] Validation of cells with defined precision](#mapping-validation-of-cells-with-defined-precision)
29
30
  * [Auto discover position feature in Mapping](#auto-discover-position-feature-in-mapping)
30
31
  * [[COLLECTION] Validation of a collection (Regular CSV)](#collection-validation-of-a-collection-regular-csv)
@@ -33,6 +34,7 @@ It is a DSL to validate and map a CSV to a Ruby Hash.
33
34
  * [CSV Headers](#csv-headers)
34
35
  * [Parser and configuration](#parser-and-configuration)
35
36
  * [Response](#response)
37
+ * [Configuration](#configuration)
36
38
  * [Exception or Not !](#exception-or-not-)
37
39
  * [On **BREAK_ON_FAILURE MODE**](#on-break_on_failure-mode)
38
40
  * [On **CSV MODE**](#on-csv-mode)
@@ -42,7 +44,7 @@ It is a DSL to validate and map a CSV to a Ruby Hash.
42
44
  * [Rule](#rule)
43
45
  * [Error](#error)
44
46
  * [Personal Validator Rule](#personal-validator-rule)
45
- * [Config file](#config-file)
47
+ * [Yaml Config file](#yaml-config-file)
46
48
  * [YamlLoader](#yamlloader)
47
49
  * [Type conversion](#type-conversion)
48
50
  * [Changes](#changes)
@@ -170,7 +172,7 @@ All remaining keys are optionals:
170
172
  * mappable: true
171
173
  * type: 'string'
172
174
  * values: nil
173
- * case_sensitive_values: true
175
+ * case_sensitive_values: true # When you define set of 'values'
174
176
  * nested: nil
175
177
  * allow_blank: false
176
178
  * extra_validator: nil
@@ -185,6 +187,19 @@ A definition should be provided. There are 2 types of definitions:
185
187
 
186
188
  ## Samples
187
189
 
190
+ ### Autodiscover generale setting
191
+
192
+ You can define your matching expression as exact match and case sensitive or not.
193
+
194
+ ```
195
+ conf.ignore_case = true # /Sex/ become /Sex/i
196
+ conf.exact_matching = true # /Sex/ become /\A(Sex)\z/
197
+ ```
198
+
199
+ Both option can be cumulated : /Sex/ can become /\A(Sex)\z/i
200
+
201
+ For further information please see section [Configuration](#configuration)
202
+
188
203
  ### [MAPPING] Validation of cells with defined precision
189
204
 
190
205
  Consider the following CSV:
@@ -259,6 +274,12 @@ became
259
274
  cell position: [[0, /Employment/],1], key: 'employment'
260
275
  ```
261
276
 
277
+ or
278
+
279
+ ```
280
+ cell position: [[0, 'Employment'],1], key: 'employment'
281
+ ```
282
+
262
283
  ### [COLLECTION] Validation of a collection (Regular CSV)
263
284
 
264
285
  Consider the following CSV:
@@ -332,6 +353,11 @@ can be change to
332
353
  cell position: /Name/ key: 'name'
333
354
  ```
334
355
 
356
+ or
357
+
358
+ ```
359
+ cell position: 'Name' key: 'name'
360
+ ```
335
361
 
336
362
  ### Structure validation rules
337
363
 
@@ -405,6 +431,34 @@ data or errors are Array, but errors can be formatted on csv format with .to_csv
405
431
  response.errors.to_csv
406
432
  ```
407
433
 
434
+ ## Configuration
435
+
436
+ You can add a configuration file on your Rails project under this directory
437
+
438
+ add file `config/initializers/csv2hash.rb`
439
+
440
+ You can use the Rails generator for this
441
+
442
+ `rails generate csh2hash:install`
443
+
444
+ ```
445
+ Csv2hash.configure do |conf|
446
+ # Conversion of values
447
+ # conf.convert = false # default: false
448
+ # conf.true_values = ['yes','y','t'] # default: ['yes','y','t']
449
+ # conf.false_values = ['no','n','f'] # default: ['no','n','f']
450
+ # conf.nil_values = ['nil','null'] # default: ['nil','null']
451
+
452
+ # Auto discover for (mapping and collection)
453
+ # conf.ignore_case = false # default: false
454
+ # conf.exact_matching = false # default: false
455
+ end
456
+ ```
457
+
458
+ For explanation of "Conversion of values" please take a look on [Type conversion](#type-conversion)
459
+
460
+ For explanation of "Auto discover for (mapping and collection)" please take a look on [Autodiscover generale setting](#autodiscover-generale-setting)
461
+
408
462
  ## Exception or Not !
409
463
 
410
464
  You can choose into 2 differents modes of parsing, either **break_on_failure mode** for throw an exception when rule fail or **csv mode** for get csv original data + errors throwing into added extra column.
@@ -509,7 +563,7 @@ Csv data
509
563
  [ [ 'Foo' ] ]
510
564
  ```
511
565
 
512
- # Config file
566
+ # Yaml Config file
513
567
 
514
568
  You can defined rules into a yaml file
515
569
 
@@ -584,31 +638,30 @@ loader.definition
584
638
 
585
639
  # Type conversion
586
640
 
587
- By default Csv2hash doesn't convert basic value, but you can activate this on configuration, for Rails use :
641
+ By default Csv2hash doesn't convert basic value, but you can activate this option `convert = true`
588
642
 
589
- add file `config/initializers/csv2hash.rb`
643
+ You can define which String are converted on `true`, `false` or `nil`
590
644
 
591
645
  ```
592
- Csv2hash.configure do |conf|
593
- conf.convert = true
594
- end
646
+ true_values = ['yes','y','t']
595
647
  ```
596
648
 
649
+ With this configuration 'Yes' become => true (Basic boolean ruby value)
650
+
597
651
  ```
598
- rails generate csh2hash:install
652
+ conf.false_values = ['no','n','f']
599
653
  ```
600
654
 
601
- If you want add your specific conversion
655
+ With this configuration 'No' become => false (Basic boolean ruby value)
602
656
 
603
657
  ```
604
- Csv2hash.configure do |conf|
605
- # conf.convert = false # default: false
606
- # conf.true_values = ['yes','y','t'] # default: ['yes','y','t']
607
- # conf.false_values = ['no','n','f'] # default: ['no','n','f']
608
- # conf.nil_values = ['nil','null'] # default: ['nil','null']
609
- end
658
+ conf.nil_values = ['nil','null']
610
659
  ```
611
660
 
661
+ With this configuration 'Null' become => nil (Basic ruby value)
662
+
663
+ For further information please see section [Configuration](#configuration)
664
+
612
665
  # Changes
613
666
 
614
667
  please refere to [CHANGELOG.md](https://github.com/FinalCAD/csv2hash/blob/master/CHANGELOG.md) doc
@@ -19,16 +19,89 @@ module Csv2hash
19
19
  end
20
20
  end
21
21
 
22
+ # Public: Extract String to Regex
23
+ #
24
+ # /Sex/ => /Sex/
25
+ # /Sex/ => /Sex/i
26
+ # /Sex/ => /\A(Sex)\z/
27
+ # /Sex/ => /\A(Sex)\z/i
28
+
29
+ # 'Sex' => /Sex/
30
+ # 'Sex' => /Sex/i
31
+ # 'Sex' => /\A(Sex)\z/
32
+ # 'Sex' => /\A(Sex)\z/i
33
+ #
34
+ # Examples
35
+ #
36
+ # deserialize_regex!
37
+ # # => position: [0 ,0]
38
+ # # => position: /Sex/
39
+ # # => position: [[0 ,/Sex/], 0]
40
+ #
41
+ # Returns Regex (See private method YamlCoercer#regexp)
22
42
  def deserialize_regex!
23
43
  y, x = self.rules.fetch :position
24
- if y.is_a?(Array)
25
- column, matcher_string = y
26
- self.rules[:position] = [[column, Regexp.new(matcher_string)],x]
27
- elsif y.is_a?(String)
28
- self.rules[:position] = Regexp.new("\\A(#{y})\\z")
44
+ # Value possible:
45
+ # * (regular) [0, 0]
46
+ # * (collection) 'Sex'
47
+ # * (mapping) [[0, 'Sex'], 0]
48
+
49
+ return if y.is_a?(Fixnum) # There are nothing to deserialized [0, 0]
50
+
51
+ # Deserialize only type of (Collection) ['Sex', 0] or (Mapping) [[0, 'Sex'], 0]
52
+ column, matching_string_expression = extract_column y
53
+
54
+ self.rules[:position] = if y.is_a?(Array)
55
+ [[column, regexp(matching_string_expression)],x] # (Mapping)
56
+ else # String or Regexp
57
+ regexp(matching_string_expression) # (Collection)
29
58
  end
30
59
  end
31
60
 
61
+ # Public: Extract if is necessary the column number.
62
+ # You have two type of position based on regex :
63
+ # * mapping: This need a column position for searching on this column the row position (search y position)
64
+ # * collection: Search in all columns for find column position (search x position)
65
+ #
66
+ # value - Array or String - example : [1,'Sex'] or 'Sex'
67
+ #
68
+ # Examples
69
+ #
70
+ # extract_column([1, 'Sex'])
71
+ # # => [1, 'Sex']
72
+ #
73
+ # extract_column('Sex')
74
+ # # => [nil, 'Sex']
75
+ #
76
+ # Returns a array with column position (type mapping) and matching string
77
+ def extract_column value
78
+ return value if value.is_a?(Array)
79
+ [nil, value]
80
+ end
81
+
82
+ # Public: Return regexp from string
83
+ #
84
+ # term - Matching String - Example : 'Sex'
85
+ #
86
+ # Examples
87
+ #
88
+ # regexp('Sex')
89
+ # # => /\A(Sex)\z/ # exact_matching: true, ignore_case: false
90
+ # # => /\A(Sex)\z/i # exact_matching: true, ignore_case: true
91
+ # # => /Sex/ # exact_matching: false, ignore_case: false
92
+ # # => /Sex/i # exact_matching: false, ignore_case: true
93
+ #
94
+ # Returns a regex depend of configuration, see
95
+ def regexp term
96
+ term = term.source if term.is_a?(Regexp)
97
+ term = "\\A(#{term})\\z" if Csv2hash.configuration.exact_matching
98
+
99
+ args = [term]
100
+ args << Regexp::IGNORECASE if Csv2hash.configuration.ignore_case
101
+
102
+ Regexp.new(*args)
103
+ end
104
+
32
105
  def deserialize_range!
33
106
  begin
34
107
  values = self.rules.fetch(:values)
@@ -5,6 +5,8 @@ module Csv2hash
5
5
  attr_accessor :nil_values
6
6
  # attr_accessor :extra_values
7
7
  attr_accessor :convert
8
+ attr_accessor :ignore_case
9
+ attr_accessor :exact_matching
8
10
 
9
11
  def initialize
10
12
  self.convert = false
@@ -12,6 +14,8 @@ module Csv2hash
12
14
  self.false_values = ['no','n','f']
13
15
  self.nil_values = ['nil','null']
14
16
  # self.extra_values = {} # { [] => }
17
+ self.ignore_case = false
18
+ self.exact_matching = false
15
19
  end
16
20
  end
17
21
  end
@@ -1,3 +1,3 @@
1
1
  module Csv2hash
2
- VERSION = '0.7.3'
2
+ VERSION = '0.7.5'
3
3
  end
@@ -1,6 +1,11 @@
1
1
  Csv2hash.configure do |conf|
2
- # conf.convert = false # default: false
3
- # conf.true_values = ['yes','y','t'] # default: ['yes','y','t']
4
- # conf.false_values = ['no','n','f'] # default: ['no','n','f']
5
- # conf.nil_values = ['nil','null'] # default: ['nil','null']
2
+ # Conversion of values
3
+ # conf.convert = false # default: false
4
+ # conf.true_values = ['yes','y','t'] # default: ['yes','y','t']
5
+ # conf.false_values = ['no','n','f'] # default: ['no','n','f']
6
+ # conf.nil_values = ['nil','null'] # default: ['nil','null']
7
+
8
+ # Auto discover for (mapping and collection)
9
+ # conf.ignore_case = false # default: false
10
+ # conf.exact_matching = false # default: false
6
11
  end
@@ -5,13 +5,31 @@ module Csv2hash
5
5
  let(:configuration) { Configuration.new }
6
6
 
7
7
  describe '#default' do
8
- let(:true_values) { ['yes','y','t'] }
9
- let(:false_values) { ['no','n','f'] }
10
- let(:nil_values) { ['nil','null'] }
8
+ let(:true_values) { ['yes','y','t'] }
9
+ let(:false_values) { ['no','n','f'] }
10
+ let(:nil_values) { ['nil','null'] }
11
+ let(:ignore_case) { false }
12
+ let(:exact_matching) { false }
11
13
 
12
14
  it 'true values' do
13
15
  expect(configuration.true_values).to eq(true_values)
14
16
  end
17
+
18
+ it 'false values' do
19
+ expect(configuration.false_values).to eq(false_values)
20
+ end
21
+
22
+ it 'nil values' do
23
+ expect(configuration.nil_values).to eq(nil_values)
24
+ end
25
+
26
+ it 'ignore_case' do
27
+ expect(configuration.ignore_case).to eq(ignore_case)
28
+ end
29
+
30
+ it 'exact_matching' do
31
+ expect(configuration.exact_matching).to eq(exact_matching)
32
+ end
15
33
  end
16
34
 
17
35
  end
@@ -3,25 +3,116 @@ require 'spec_helper'
3
3
  module Csv2hash
4
4
  module Coercers
5
5
  describe YamlCoercer do
6
- context 'when position is a string' do
7
- let(:rules) { {:position=>"Mobile phone number", :key=>"mobile_phone", :allow_blank=>true} }
8
- let(:result_rules) { {:position=>/\A(Mobile phone number)\z/, :key=>"mobile_phone", :allow_blank=>true} }
6
+ let(:base_rules) {{ key: 'mobile_phone', allow_blank: true }}
7
+ let(:ignore_case) { false }
8
+ let(:exact_matching) { false }
9
+
10
+ context 'deserialize!' do
9
11
  subject { YamlCoercer.new(rules) }
12
+ before do
13
+ Csv2hash.configure do |conf|
14
+ conf.ignore_case = ignore_case
15
+ conf.exact_matching = exact_matching
16
+ end
17
+ subject.deserialize!
18
+ end
10
19
 
11
- before { subject.deserialize! }
12
-
13
- it{expect(subject.rules).to eql(result_rules)}
14
- end
20
+ after do
21
+ Csv2hash.configure do |conf|
22
+ conf.ignore_case = false
23
+ conf.exact_matching = false
24
+ end
25
+ end
15
26
 
16
- context 'when position is a array' do
17
- let(:rules) { {:position=>[[1,"Mobile phone number"],2], :key=>"mobile_phone", :allow_blank=>true} }
18
- let(:result_rules) { {:position=>[[1, /Mobile phone number/], 2], :key=>"mobile_phone", :allow_blank=>true} }
19
- subject { YamlCoercer.new(rules) }
27
+ context 'regular' do
28
+ context 'from string' do
29
+ context 'when position is a string' do
30
+ let(:rules) { base_rules.merge(position: 'Mobile phone number') }
31
+ let(:result_rules) { base_rules.merge(position: /Mobile phone number/) }
32
+
33
+ it { expect(subject.rules).to eql(result_rules) }
34
+ end
35
+
36
+ context 'when position is a array' do
37
+ let(:rules) { base_rules.merge(position: [[1, 'Mobile phone number'], 2]) }
38
+ let(:result_rules) { base_rules.merge(position: [[1, /Mobile phone number/], 2]) }
39
+
40
+ it { expect(subject.rules).to eql(result_rules) }
41
+ end
42
+ end
43
+ context 'from regex' do
44
+ context 'when position is a string' do
45
+ let(:rules) { base_rules.merge(position: /Mobile phone number/) }
46
+ let(:result_rules) { base_rules.merge(position: /Mobile phone number/) }
47
+
48
+ it { expect(subject.rules).to eql(result_rules) }
49
+ end
50
+
51
+ context 'when position is a array' do
52
+ let(:rules) { base_rules.merge(position: [[1, /Mobile phone number/], 2]) }
53
+ let(:result_rules) { base_rules.merge(position: [[1, /Mobile phone number/], 2]) }
54
+
55
+ it { expect(subject.rules).to eql(result_rules) }
56
+ end
57
+ end
58
+ end
59
+
60
+ context 'ignore_case' do
61
+ let(:ignore_case) { true }
62
+
63
+ context 'when position is a string' do
64
+ let(:rules) { base_rules.merge(position: 'Mobile phone number') }
65
+ let(:result_rules) { base_rules.merge(position: /Mobile phone number/i) }
66
+
67
+ it { expect(subject.rules).to eql(result_rules) }
68
+ end
69
+
70
+ context 'when position is a array' do
71
+ let(:rules) { base_rules.merge(position: [[1, 'Mobile phone number'], 2]) }
72
+ let(:result_rules) { base_rules.merge(position: [[1, /Mobile phone number/i], 2]) }
73
+
74
+ it { expect(subject.rules).to eql(result_rules) }
75
+ end
76
+ end
77
+
78
+ context 'exact_matching' do
79
+ let(:exact_matching) { true }
80
+
81
+ context 'when position is a string' do
82
+ let(:rules) { base_rules.merge(position: 'Mobile phone number') }
83
+ let(:result_rules) { base_rules.merge(position: /\A(Mobile phone number)\z/) }
84
+
85
+ it { expect(subject.rules).to eql(result_rules) }
86
+ end
87
+
88
+ context 'when position is a array' do
89
+ let(:rules) { base_rules.merge(position: [[1, 'Mobile phone number'], 2]) }
90
+ let(:result_rules) { base_rules.merge(position: [[1, /\A(Mobile phone number)\z/], 2]) }
91
+
92
+ it { expect(subject.rules).to eql(result_rules) }
93
+ end
94
+ end
95
+
96
+ context 'exact_matching and ignore_case' do
97
+ let(:ignore_case) { true }
98
+ let(:exact_matching) { true }
99
+
100
+ context 'when position is a string' do
101
+ let(:rules) { base_rules.merge(position: 'Mobile phone number') }
102
+ let(:result_rules) { base_rules.merge(position: /\A(Mobile phone number)\z/i) }
103
+
104
+ it { expect(subject.rules).to eql(result_rules) }
105
+ end
106
+
107
+ context 'when position is a array' do
108
+ let(:rules) { base_rules.merge(position: [[1, 'Mobile phone number'], 2]) }
109
+ let(:result_rules) { base_rules.merge(position: [[1, /\A(Mobile phone number)\z/i], 2]) }
110
+
111
+ it { expect(subject.rules).to eql(result_rules) }
112
+ end
113
+ end
20
114
 
21
- before { subject.deserialize! }
22
-
23
- it{expect(subject.rules).to eql(result_rules)}
24
- end
115
+ end
25
116
  end
26
117
  end
27
118
  end
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.7.3
4
+ version: 0.7.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joel AZEMAR
@@ -14,70 +14,70 @@ dependencies:
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: '4.1'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: '4.1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">"
31
+ - - '>'
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.3'
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
40
  version: '1.3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
47
  version: '10.3'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ~>
53
53
  - !ruby/object:Gem::Version
54
54
  version: '10.3'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ~>
60
60
  - !ruby/object:Gem::Version
61
61
  version: '3.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ~>
67
67
  - !ruby/object:Gem::Version
68
68
  version: '3.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: its
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ~>
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0.2'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ~>
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0.2'
83
83
  description: DSL to map a CSV to a Ruby Hash
@@ -89,14 +89,14 @@ executables:
89
89
  extensions: []
90
90
  extra_rdoc_files: []
91
91
  files:
92
- - ".coveralls.yml"
93
- - ".gitignore"
94
- - ".rspec"
95
- - ".travis.yml"
96
- - ".yardoc/checksums"
97
- - ".yardoc/object_types"
98
- - ".yardoc/objects/root.dat"
99
- - ".yardoc/proxy_types"
92
+ - .coveralls.yml
93
+ - .gitignore
94
+ - .rspec
95
+ - .travis.yml
96
+ - .yardoc/checksums
97
+ - .yardoc/object_types
98
+ - .yardoc/objects/root.dat
99
+ - .yardoc/proxy_types
100
100
  - CHANGELOG.md
101
101
  - Gemfile
102
102
  - Gemfile.lock
@@ -172,17 +172,17 @@ require_paths:
172
172
  - lib
173
173
  required_ruby_version: !ruby/object:Gem::Requirement
174
174
  requirements:
175
- - - ">="
175
+ - - '>='
176
176
  - !ruby/object:Gem::Version
177
177
  version: '0'
178
178
  required_rubygems_version: !ruby/object:Gem::Requirement
179
179
  requirements:
180
- - - ">="
180
+ - - '>='
181
181
  - !ruby/object:Gem::Version
182
182
  version: '0'
183
183
  requirements: []
184
184
  rubyforge_project:
185
- rubygems_version: 2.2.2
185
+ rubygems_version: 2.0.14
186
186
  signing_key:
187
187
  specification_version: 4
188
188
  summary: Mapping a CSV to a Ruby Hash