README.md in csv2hash-0.2.0 vs README.md in csv2hash-0.2.1
- old
+ new
@@ -33,33 +33,33 @@
You should declare a definition for you CSV, and then define for each cell what you would expect.
Example :
-You want the cell located on first line, first column to be a string with its values to be 'yes' or 'no'. Then you can right the following validation rule :
+If you want the very first cell, located on the first line and on the first column to be a string with values are either 'yes' either 'no', you can write the following validation rule:
{ name: 'aswering', type: 'string', values: ['yes', 'no'], position: [0,0] }
-The type is 'string' by default, so can just write:
+:type attribute has 'string' for default value, therefore you can just write this:
{ name: 'aswering', values: ['yes', 'no'], position: [0,0] }
-You can define a message, default is 'undefined :key on :position'
+You can define you own message but default message is 'undefined :key on :position'
{ name: 'aswering', values: ['yes', 'no'], position: [0,0], message: 'this value is not supported' }
-You can also define Range
+You can also define Range of values
{ name: 'score', values: 0..5, position: [0,0] }
The message is parsed:
{ ..., message: 'value of :name is not supported, please you one of :values' }
It produces :
- value of aswering is not supported, please you one of [yes, no]
+ value of answering is not supported, please use one of [yes, no]
### Default values
Only position is required:
@@ -83,11 +83,11 @@
* search for data at a precise position in the table: `y,x`
* or search for data in a column of rows, where all the rows are the same: `x` (column index)
## Samples
-### Validation of a cell at a precise position
+### Validation of cells with defined precision
Consider the following CSV:
| Fields | Person Informations | Optional |
|-------------|----------------------|----------|
@@ -123,11 +123,11 @@
Csv2Hash::Definition.new(rules, type = Csv2Hash::Definition::MAPPING, header_size: 1)
end
end
-### Validation of a collection
+### Validation of a collection (Regular CSV)
Consider the following CSV:
| Nickname | First Name | Last Name |
|----------|------------|-----------|
@@ -162,11 +162,10 @@
Csv2Hash::Definition.new(rules, type = Csv2Hash::Definition::COLLECTION, header_size: 1)
end
end
-
### Structure validation rules
You may want to validate some structure, like min or max number of columns, definition accepts structure_rules as a key for the third parameter.
Current validations are: MinColumn, MaxColumn
@@ -191,32 +190,32 @@
mapping << { position: 2, key: 'last_name' }
end
end
def definition
- Csv2Hash::Definition.new(rules, type = Csv2Hash::Definition::COLLECTION, structure_rules: {'MinColumn' => 2, 'MaxColumn' => 3})
+ Csv2Hash::Definition.new(rules, type = Csv2Hash::Definition::COLLECTION, structure_rules: { 'MinColumns' => 2, 'MaxColumns' => 3 })
end
end
### CSV Headers
You can define the number of rows to skip in the header of the CSV.
- Definition.new(rules, type, header_size=0)
+ Definition.new(rules, type, header_size: 0)
### Parser and configuration
-Pasrer take severale parameters like that :
+Pasrer can take several parameters like that:
- initialize definition, file_path, exception_mode=true, data_source=nil, ignore_blank_line=false
+ definition, file_path, exception_mode=true, data_source=nil, ignore_blank_line=false
-you can pass directly Array of data (Array at 2 dimensions) really useful for testing, if you don't care about line blank in your CSV you can ignore them.
+you can pass directly Array of data (Array at 2 dimensions) really useful for testing, if you don't care about blank lines in your CSV you can ignore them.
### Response
-The parser return values wrapper into DataWrapper Object, you can call .valid? method on this Object and grab either data or errors like that :
+The parser return values wrapper into DataWrapper Object, you can call ```.valid?``` method on this Object and grab either data or errors like that :
response = parser.parse
if response.valid?
response.data
else
@@ -227,24 +226,24 @@
response.errors.to_csv
## Exception or Not !
-You can choice 2 modes of parsing, either **exception mode** for raise exception in first breaking rules or **csv mode** for get csv original data + errors throwing into added columns.
+You can choose into 2 different modes of parsing, either **exception mode** for raise exception in first breaking rules or **csv mode** for get csv original data + errors throwing into added columns.
### On **CSV MODE** you can choose different way for manage errors
-`.parse()` return `data_wrapper` if `.parse()` is invalid, you can code your own behavior like that :
+`.parse()` return `data_wrapper` if `.parse()` is invalid, you can code your own behavior:
in your code
parser = Csv2hash.new(definition, 'file_path').new
response = parser.parse
return response if response.valid?
# Whatever
-In the same time Csv2hash call **notify(response)** method when CSV parsing fail, you can add your own Notifier like that
+In the same time Csv2hash call **notify(response)** method when CSV parsing fail, you can add your own Notifier:
module Csv2hash
module Plugins
class Notifier
def initialize csv2hash
@@ -285,10 +284,11 @@
{ position: [1,1], key: 'nickname', allow_blank: false }
### Error
{ y: 1, x: 1, message: 'undefined nikcname on [0, 0]', key: 'nickname', value: nil }
+
## Personal Validator Rule
You can define your own Validator
For downcase validation
@@ -300,19 +300,18 @@
end
in your rule
{ position: [0,0], key: 'name', extra_validator: DowncaseValidator.new,
- message: 'your data should be writting in downcase only' }
+ message: 'your data should be written in lowercase only.' }
Csv data
[ [ 'Foo' ] ]
+# Upgrading from 0.1 to 0.2
-### Upgrading from 0.1 to 0.2
-
-The signature of Definition#initialize changed, as last parameter is a configuration hash, while in versions prior to 0.2 it was an integer (header_size) consider upgrading your code :
+The signature of Definition#new has changed, the last parameter is a configuration hash, while in versions prior to 0.2 it was an integer (header_size) consider upgrading your code :
Prior to 0.2 :
```
Csv2Hash::Definition.new(rules, type = Csv2Hash::Definition::COLLECTION, 1)
\ No newline at end of file