README.md in csv_decision-0.1.0 vs README.md in csv_decision-0.2.0
- old
+ new
@@ -196,11 +196,11 @@
DATA
```
These comparison operators are also supported: `!=`, `>`, `>=`, `<`, `<=`.
For more simple examples see `spec/csv_decision/examples_spec.rb`.
-#### Input guard conditions
+#### Input `guard` conditions
Sometimes it's more convenient to write guard expressions in a single column specialized for that purpose.
For example:
```ruby
data = <<~DATA
@@ -220,11 +220,11 @@
```
Input `guard:` columns may be anonymous, and must contain non-constant expressions. In addition to
0-arity Ruby methods, the following comparison operators are allowed: `==`, `!=`,
`>`, `>=`, `<` and `<=`. Also, regular expressions are supported - i.e., `=~` and `!~`.
-#### Output if conditions
+#### Output `if` conditions
In some situations it is useful to apply filter conditions *after* all the output
columns have been derived. For example:
```ruby
data = <<~DATA
@@ -243,9 +243,33 @@
```
Output `if:` columns may be anonymous, and must contain non-constant expressions. In addition to
0-arity Ruby methods, the following comparison operators are allowed: `==`, `!=`,
`>`, `>=`, `<` and `<=`. Also, regular expressions are supported - i.e., `=~` and `!~`.
+#### Input `set` columns
+
+If you wish to set default values in the input hash, you can use a `set` column rather
+than an `in` column. The data row beneath the header is used to specify the default expression.
+There are three variations: `set` (unconditional default) `set/nil?`(set if `nil?` true)
+and `set/blank?` (set if `blank?` true).
+Note that the `decide!` method will mutate the input hash.
+
+```ruby
+data = <<~DATA
+ set/nil? :country, guard:, set: class, out :PAID, out: len, if:
+ US, , :class.upcase,
+ US, :CUSIP.present?, != PRIVATE, :CUSIP, :PAID.length, :len == 9
+ !=US, :ISIN.present?, != PRIVATE, :ISIN, :PAID.length, :len == 12
+ US, :CUSIP.present?, PRIVATE, :CUSIP, :PAID.length,
+ !=US, :ISIN.present?, PRIVATE, :ISIN, :PAID.length,
+DATA
+
+table = CSVDecision.parse(data)
+table.decide(CUSIP: '1234567890', class: 'Private') #=> {PAID: '1234567890', len: 10}
+table.decide(ISIN: '123456789012', country: 'GB', class: 'private') #=> {PAID: '123456789012', len: 12}
+
+```
+
### Testing
`csv_decision` includes thorough [RSpec](http://rspec.info) tests:
```bash
\ No newline at end of file