csv2hash 0.6.7 → 0.6.8

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: 332e1760a8872c909fea63cc52a8701580ab1c50
4
- data.tar.gz: 5c40139eef7283dbb3505b2557c539a4a9fb16c0
3
+ metadata.gz: 7c09804fb3f85eacdc90cbfa95ccee0acc8a4fb8
4
+ data.tar.gz: d29ac384ef4275b13e087fd0eb504eba2f93d337
5
5
  SHA512:
6
- metadata.gz: d468a06d1114d8b16f283ea2f06ce08774cfa769eb761e4bb8c6a1f2f78431461c59f31d2ab4c79900ab500546c7c2666bc11a9ea0597ad8550a76c31bf01e8e
7
- data.tar.gz: c6e8e3297d875cd2fda25ae025282df0a233170c3543c3d110280e30c8e4d7aedda4e0008941a258473aa5bc844547383b171169205b691ee65008f685a6a1fd
6
+ metadata.gz: f2b07b5cfcb24197dec4195873a285f353974960ba29deee2a805da2ee45ce5c8a09838ec04b49fab4e6683672226b46587808ffdaacf066b3c6770f139451e1
7
+ data.tar.gz: 5f2fda3e1d08e971ad39ad05bcfbf094f29d1d2e5ca9a86a42cf413d5c7eb502a2ce08bdcfca25c0f1afa5ccd31fe4410bea0cc190ff53fec83e1b7bc319dc54
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ### VERSION 0.6.8
2
+
3
+ * bug fix
4
+ * fix typo on generator
5
+
1
6
  ### VERSION 0.6.7
2
7
 
3
8
  * enhancements
data/Gemfile CHANGED
@@ -5,7 +5,7 @@ gemspec
5
5
  group :test do
6
6
  gem 'coveralls', require: false
7
7
  gem 'pry'
8
- # gem 'rails'
8
+ gem 'generator_spec'
9
9
  end
10
10
 
11
11
  group :doc do
data/Gemfile.lock CHANGED
@@ -1,18 +1,28 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- csv2hash (0.6.7)
4
+ csv2hash (0.6.8)
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)
13
+ rack (~> 1.5.2)
14
+ rack-test (~> 0.6.2)
15
+ actionview (4.1.6)
16
+ activesupport (= 4.1.6)
17
+ builder (~> 3.1)
18
+ erubis (~> 2.7.0)
10
19
  activesupport (4.1.6)
11
20
  i18n (~> 0.6, >= 0.6.9)
12
21
  json (~> 1.7, >= 1.7.7)
13
22
  minitest (~> 5.1)
14
23
  thread_safe (~> 0.1)
15
24
  tzinfo (~> 1.1)
25
+ builder (3.2.2)
16
26
  coderay (1.1.0)
17
27
  coveralls (0.7.1)
18
28
  multi_json (~> 1.3)
@@ -22,6 +32,10 @@ GEM
22
32
  thor
23
33
  diff-lcs (1.2.5)
24
34
  docile (1.1.5)
35
+ erubis (2.7.0)
36
+ generator_spec (0.9.2)
37
+ activesupport (>= 3.0.0)
38
+ railties (>= 3.0.0)
25
39
  i18n (0.6.11)
26
40
  inch (0.4.10)
27
41
  pry
@@ -33,13 +47,21 @@ GEM
33
47
  json (1.8.1)
34
48
  method_source (0.8.2)
35
49
  mime-types (2.3)
36
- minitest (5.4.1)
50
+ minitest (5.4.2)
37
51
  multi_json (1.10.1)
38
52
  netrc (0.7.7)
39
53
  pry (0.10.1)
40
54
  coderay (~> 1.1.0)
41
55
  method_source (~> 0.8.1)
42
56
  slop (~> 3.4)
57
+ rack (1.5.2)
58
+ rack-test (0.6.2)
59
+ rack (>= 1.0)
60
+ railties (4.1.6)
61
+ actionpack (= 4.1.6)
62
+ activesupport (= 4.1.6)
63
+ rake (>= 0.8.7)
64
+ thor (>= 0.18.1, < 2.0)
43
65
  rake (10.3.2)
44
66
  rest-client (1.7.2)
45
67
  mime-types (>= 1.16, < 3.0)
@@ -83,6 +105,7 @@ DEPENDENCIES
83
105
  bundler (~> 1.6)
84
106
  coveralls
85
107
  csv2hash!
108
+ generator_spec
86
109
  inch
87
110
  its (~> 0.2)
88
111
  pry
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Csv2Hash
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/csv2hash.svg)](http://badge.fury.io/rb/csv2hash)
4
+
3
5
  [![Code Climate](https://codeclimate.com/github/FinalCAD/csv2hash.png)](https://codeclimate.com/github/FinalCAD/csv2hash)
4
6
 
5
7
  [![Dependency Status](https://gemnasium.com/FinalCAD/csv2hash.png)](https://gemnasium.com/FinalCAD/csv2hash)
@@ -10,6 +12,43 @@
10
12
 
11
13
  It is a DSL to validate and map a CSV to a Ruby Hash.
12
14
 
15
+ # Summary
16
+
17
+ * [Csv2Hash](#csv2hash)
18
+ * [Summary](#summary)
19
+ * [Installation](#installation)
20
+ * [Usage](#usage)
21
+ * [Invoke parser](#invoke-parser)
22
+ * [Parser options](#parser-options)
23
+ * [Definition DSL](#definition-dsl)
24
+ * [Definition Rules](#definition-rules)
25
+ * [Default rules values](#default-rules-values)
26
+ * [define where your data are expected](#define-where-your-data-are-expected)
27
+ * [Samples](#samples)
28
+ * [[MAPPING] Validation of cells with defined precision](#mapping-validation-of-cells-with-defined-precision)
29
+ * [Auto discover position feature](#auto-discover-position-feature)
30
+ * [[COLLECTION] Validation of a collection (Regular CSV)](#collection-validation-of-a-collection-regular-csv)
31
+ * [Structure validation rules](#structure-validation-rules)
32
+ * [CSV Headers](#csv-headers)
33
+ * [Parser and configuration](#parser-and-configuration)
34
+ * [Response](#response)
35
+ * [Exception or Not !](#exception-or-not-)
36
+ * [On **BREAK_ON_FAILURE MODE**](#on-break_on_failure-mode)
37
+ * [On **CSV MODE**](#on-csv-mode)
38
+ * [Errors Format](#errors-format)
39
+ * [Sample](#sample)
40
+ * [Csv data](#csv-data)
41
+ * [Rule](#rule)
42
+ * [Error](#error)
43
+ * [Personal Validator Rule](#personal-validator-rule)
44
+ * [Config file](#config-file)
45
+ * [YamlLoader](#yamlloader)
46
+ * [Type conversion](#type-conversion)
47
+ * [Changes](#changes)
48
+ * [Upgrading](#upgrading)
49
+ * [Yard doc](#yard-doc)
50
+ * [Contributing](#contributing)
51
+
13
52
  ## Installation
14
53
 
15
54
  Add this line to your application's Gemfile:
@@ -28,7 +67,25 @@ Or install it yourself as:
28
67
 
29
68
  Parsing is based on rules, you should defined rule for each cells
30
69
 
31
- ### DSL
70
+ ### Invoke parser
71
+
72
+ ```
73
+ Csv2hash::Main.new(:<definition_name>, file_path_or_data, options).parse
74
+ ```
75
+
76
+ ```
77
+ Csv2hash::Main.new(:<definition_name>, options) do
78
+ file_path_or_data
79
+ end.parse
80
+ ```
81
+
82
+ ### Parser options
83
+
84
+ List of options :
85
+
86
+ * `ignore_blank_line: :boolean` # i think is pretty straightforward to understand
87
+
88
+ ### Definition DSL
32
89
 
33
90
  ```
34
91
  Csv2hash::Main.generate_definition :name do
@@ -43,7 +100,7 @@ end
43
100
  Csv2hash::Main[:name] # Access anywhere
44
101
  ```
45
102
 
46
- ### Rules
103
+ ### Definition Rules
47
104
 
48
105
  You should declared a definition of your CSV file, and then define for each cell what you would expect.
49
106
 
@@ -85,7 +142,7 @@ It produces :
85
142
  value of answering is not supported, please use one of [yes, no]
86
143
  ```
87
144
 
88
- ### Default values
145
+ ### Default rules values
89
146
 
90
147
  Only position is required:
91
148
 
@@ -101,7 +158,7 @@ All remaining keys are optionals:
101
158
  * allow_blank: false
102
159
  * extra_validator: nil
103
160
 
104
- ## Define where your data is expected
161
+ ### Define where your data are expected
105
162
 
106
163
  **IMPORTANT!** Position means [Y, X], where Y is rows, X columns
107
164
 
@@ -109,24 +166,6 @@ A definition should be provided. There are 2 types of definitions:
109
166
  * search for data at a precise position in the table: `y,x`
110
167
  * or search for data in a column of rows, where all the rows are the same: `x` (column index)
111
168
 
112
- ## Invoke
113
-
114
- ```
115
- Csv2hash::Main.new(:<definition_name>, file_path_or_data, options).parse
116
- ```
117
-
118
- ```
119
- Csv2hash::Main.new(:<definition_name>, options) do
120
- file_path_or_data
121
- end.parse
122
- ```
123
-
124
- ### Options
125
-
126
- List of options :
127
-
128
- * ignore_blank_line: :boolean # i think is pretty straightforward to understand
129
-
130
169
  ## Samples
131
170
 
132
171
  ### [MAPPING] Validation of cells with defined precision
@@ -171,7 +210,7 @@ class MyParser
171
210
  end
172
211
  ```
173
212
 
174
- ### Auto discover position
213
+ ### Auto discover position feature
175
214
 
176
215
  This is a special feature for finding the Y index of row where you data start. For instance you have this following data :
177
216
 
@@ -376,9 +415,9 @@ errors is a Array of Hash
376
415
  { y: 1, x: 0, message: 'message', key: 'key', value: '' }
377
416
  ```
378
417
 
379
- ## Sample
418
+ #### Sample
380
419
 
381
- ### Csv data
420
+ ##### Csv data
382
421
 
383
422
  ```
384
423
  | Fields | Person Informations |
@@ -386,13 +425,13 @@ errors is a Array of Hash
386
425
  | Nickname | nil |
387
426
  ```
388
427
 
389
- ### Rule
428
+ ##### Rule
390
429
 
391
430
  ```
392
431
  cell position: [1,1], key: 'nickname', allow_blank: false
393
432
  ```
394
433
 
395
- ### Error
434
+ ##### Error
396
435
 
397
436
  ```
398
437
  { y: 1, x: 1, message: 'undefined nikcname on [0, 0]', key: 'nickname', value: nil }
@@ -516,6 +555,15 @@ rails generate csh2hash:install
516
555
 
517
556
  If you want add your specific conversion
518
557
 
558
+ ```
559
+ Csv2hash.configure do |conf|
560
+ # conf.convert = false # default: false
561
+ # conf.true_values = ['yes','y','t'] # default: ['yes','y','t']
562
+ # conf.false_values = ['no','n','f'] # default: ['no','n','f']
563
+ # conf.nil_values = ['nil','null'] # default: ['nil','null']
564
+ end
565
+ ```
566
+
519
567
  # Changes
520
568
 
521
569
  please refere to [CHANGELOG.md](https://github.com/FinalCAD/csv2hash/blob/master/CHANGELOG.md) doc
data/UPGRADE.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Upgrading
2
2
 
3
+ # Upgrading from 0.6.7 to 0.6.8
4
+
5
+ nothing
6
+
3
7
  # Upgrading from 0.6.6 to 0.6.7
4
8
 
5
9
  nothing
@@ -1,3 +1,3 @@
1
1
  module Csv2hash
2
- VERSION = '0.6.7'
2
+ VERSION = '0.6.8'
3
3
  end
@@ -1,10 +1,10 @@
1
1
  module Csv2hash
2
- module Generator
2
+ module Generators
3
3
  class InstallGenerator < Rails::Generators::Base
4
4
  source_root File.expand_path('../templates', __FILE__)
5
5
 
6
6
  desc <<DESC
7
- description:
7
+ description :
8
8
  copy csv2hash configuration to an initializer.
9
9
  DESC
10
10
  def create_configuration
@@ -0,0 +1,36 @@
1
+ require 'rails/generators'
2
+ require 'generator_spec'
3
+
4
+ # Generators are not automatically loaded by Rails
5
+ require_relative '../../../../lib/generators/csv2hash/install/install_generator'
6
+
7
+ module Csv2hash
8
+ module Generators
9
+ describe InstallGenerator do
10
+ # Tell the generator where to put its output (what it thinks of as Rails.root)
11
+ destination File.expand_path('../../../../tmp', __FILE__)
12
+
13
+ before do
14
+ prepare_destination
15
+ run_generator
16
+ end
17
+
18
+ after do
19
+ FileUtils.rm_rf destination_root
20
+ end
21
+
22
+ specify do
23
+ expect(destination_root).to have_structure do
24
+ no_file 'csv2hash.rb'
25
+ directory 'config' do
26
+ directory 'initializers' do
27
+ file 'csv2hash.rb' do
28
+ contains 'Csv2hash.configure'
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ 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.6.7
4
+ version: 0.6.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joel AZEMAR
@@ -157,9 +157,9 @@ files:
157
157
  - spec/csv2hash/validator_spec.rb
158
158
  - spec/csv2hash/yaml_loader_spec.rb
159
159
  - spec/csv2hash_spec.rb
160
- - spec/generators/csv2hash/install_generator_spec.rb
161
160
  - spec/generators_helper.rb
162
161
  - spec/lib/extra_validators/downcase_validator.rb
162
+ - spec/lib/generators/csv2hash/install_generator_spec.rb
163
163
  - spec/spec_helper.rb
164
164
  homepage: https://github.com/joel/csv2hash
165
165
  licenses:
@@ -181,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
181
181
  version: '0'
182
182
  requirements: []
183
183
  rubyforge_project:
184
- rubygems_version: 2.2.2
184
+ rubygems_version: 2.4.2
185
185
  signing_key:
186
186
  specification_version: 4
187
187
  summary: Mapping a CSV to a Ruby Hash
@@ -198,8 +198,8 @@ test_files:
198
198
  - spec/csv2hash/validator_spec.rb
199
199
  - spec/csv2hash/yaml_loader_spec.rb
200
200
  - spec/csv2hash_spec.rb
201
- - spec/generators/csv2hash/install_generator_spec.rb
202
201
  - spec/generators_helper.rb
203
202
  - spec/lib/extra_validators/downcase_validator.rb
203
+ - spec/lib/generators/csv2hash/install_generator_spec.rb
204
204
  - spec/spec_helper.rb
205
205
  has_rdoc:
@@ -1,32 +0,0 @@
1
- # require 'generators_helper'
2
- #
3
- # # Generators are not automatically loaded by Rails
4
- # require 'generators/csv2hash/install_generator'
5
- #
6
- # describe Csv2hash::Generators::InstallGenerator do
7
- # # Tell the generator where to put its output (what it thinks of as Rails.root)
8
- # destination File.expand_path('../../../tmp', __FILE__)
9
- # teardown :cleanup_destination_root
10
- #
11
- # before {
12
- # prepare_destination
13
- # }
14
- #
15
- # def cleanup_destination_root
16
- # FileUtils.rm_rf destination_root
17
- # end
18
- #
19
- # describe '...' do
20
- # before { run_generator }
21
- #
22
- # describe 'config/initializers/csv2hash.rb' do
23
- # subject { file('config/initializers/csv2hash.rb') }
24
- # it { should exist }
25
- # it { should contain "Csv2hash.configure do |config|"}
26
- # # it { should contain "# conf.convert = false" }
27
- # # it { should contain "# conf.true_values = ['yes','y','t']" }
28
- # # it { should contain "# conf.false_values = ['no','n','f']" }
29
- # # it { should contain "# conf.nil_values = ['nil','null']" }
30
- # end
31
- # end
32
- # end