README.md in csv2hash-0.6.2 vs README.md in csv2hash-0.6.3
- old
+ new
@@ -32,11 +32,11 @@
```
Csv2hash::Main.generate_definition :name do
set_type { Definition::MAPPING }
set_header_size { 2 } # 0 by default
- set_structure_rules {{ 'MaxColumns' => 2 }}
+ set_structure_rules {{ max_columns: 2 }}
mapping do
cell position: [0,0], key: 'gender'
cell position: [1,0], key: 'name'
end
end
@@ -113,15 +113,17 @@
### [MAPPING] Validation of cells with defined precision
Consider the following CSV:
+```
| Fields | Person Informations | Optional |
|-------------|----------------------|----------|
| Nickname | jo | no |
| First Name | John | yes |
| Last Name | Doe | yes |
+```
Precise position validation sample:
```
class MyParser
@@ -131,11 +133,11 @@
def initialize file_path_or_data
@file_path_or_data = file_path_or_data
end
def data
- @data_wrapper ||= Csv2hash::Main.new(Csv2hash::Main[:<definition_name>], file_path_or_data).parse
+ @data_wrapper ||= Csv2hash::Main.new(:<definition_name>, file_path_or_data).parse
end
private
def definition
@@ -155,10 +157,11 @@
### Auto discover position
This is a special feature for finding the Y index of row where you data start. For instance you have this following data :
+```
|---------------|---------------|------|-----|
| Nickname | jo | | |
| First Name | John | | |
| Last Name | Doe | | |
| | | | |
@@ -166,10 +169,11 @@
| Post | Doe | | |
| | | | |
| | Personal info | Age | 26 |
| | Sex | Male | |
| | | | |
+```
You want extract `Employment` information and `Personal info` but we do not know if extra information will not come and break our index. This feature can be useful is this case.
You must change Y position (rows) by the column index and regex, the parser will search on this column the index row of this regex, here our rule :
@@ -185,14 +189,16 @@
### [COLLECTION] Validation of a collection (Regular CSV)
Consider the following CSV:
+```
| Nickname | First Name | Last Name |
|----------|------------|-----------|
| jo | John | Doe |
| ja | Jane | Doe |
+```
Collection validation sample:
```
class MyParser
@@ -202,11 +208,11 @@
def initialize file_path_or_data
@file_path_or_data = file_path_or_data
end
def data
- @data_wrapper ||= Csv2hash::Main.new(Csv2hash::Main[:<definition_name>], file_path_or_data).parse
+ @data_wrapper ||= Csv2hash::Main.new(:<definition_name>, file_path_or_data).parse
end
private
def definition
@@ -242,11 +248,11 @@
def initialize file_path_or_data
@file_path_or_data = file_path_or_data
end
def data
- @data_wrapper ||= Csv2hash::Main.new(Csv2hash::Main[:<definition_name>], file_path_or_data).parse
+ @data_wrapper ||= Csv2hash::Main.new(:<definition_name>, file_path_or_data).parse
end
private
def definition
@@ -359,13 +365,15 @@
## Sample
### Csv data
+```
| Fields | Person Informations |
|-------------|----------------------|
| Nickname | nil |
+```
### Rule
```
cell position: [1,1], key: 'nickname', allow_blank: false
@@ -402,16 +410,36 @@
```
[ [ 'Foo' ] ]
```
+# Config file
+
+You can defined rules into a yaml file
+
+```
+name: 'example'
+mapping: 'mapping'
+header_size: 2
+structure_rules: { max_columns: 20 }
+rules:
+ - { position: [1,1], key: 'first_name' }
+ - { position: [2,1], key: 'first_name' }
+```
+
# Changes
please refere to [CHANGELOG.md](https://github.com/FinalCAD/csv2hash/blob/master/CHANGELOG.md) doc
# Upgrading
please refere to [UPGRADE.md](https://github.com/FinalCAD/csv2hash/blob/master/UPGRADE.md) doc
+
+# Yard doc
+
+```
+bundle exec yard --plugin tomdoc
+```
## Contributing
1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)