heuristics 0.0.3 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +9 -8
- data/lib/heuristics/version.rb +1 -1
- metadata +1 -1
data/README.md
CHANGED
@@ -3,13 +3,13 @@
|
|
3
3
|
This gem allows you to define a set of conditions and test values against them.
|
4
4
|
A typical simple example can look like this:
|
5
5
|
|
6
|
-
require 'chronic'
|
6
|
+
require 'chronic'
|
7
7
|
Heuristics.define(:field_tester) do
|
8
8
|
assume_default :integer
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
|
10
|
+
assume(:date) { condition { Chronic.parse(value) } }
|
11
|
+
assume(:string) { condition { value.instance_of? String } }
|
12
|
+
assume(:hash) { condition { value.instance_of? Hash } }
|
13
13
|
end
|
14
14
|
|
15
15
|
Then you can use it like this
|
@@ -47,9 +47,6 @@ Or install it yourself as:
|
|
47
47
|
# Default value to return if no assumptions match
|
48
48
|
assume_default :integer
|
49
49
|
|
50
|
-
# An assumption that will return :string if all conditions return true
|
51
|
-
assume(:string) { condition { value.instance_of? String } }
|
52
|
-
|
53
50
|
# Assummption with multiple conditions. Returns :hash_with_values
|
54
51
|
# if all conditions return true
|
55
52
|
assume(:hash_with_values) do
|
@@ -59,10 +56,14 @@ Or install it yourself as:
|
|
59
56
|
|
60
57
|
# An assumption that will return :date if all conditions return true
|
61
58
|
assume(:date) { condition { Chronic.parse(value) != nil } }
|
59
|
+
|
60
|
+
# An assumption that will return :string if all conditions return true
|
61
|
+
assume(:string) { condition { value.instance_of? String } }
|
62
62
|
end
|
63
63
|
|
64
64
|
|
65
65
|
# Test a value against heuristic named :field_tester
|
66
|
+
# First assumption to test true for all conditions will win
|
66
67
|
# Returns :hash_with_values in this case
|
67
68
|
Heuristics.test(:field_tester, {a: 1})
|
68
69
|
|
data/lib/heuristics/version.rb
CHANGED