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.
Files changed (3) hide show
  1. data/README.md +9 -8
  2. data/lib/heuristics/version.rb +1 -1
  3. 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' # Excellent date lib to recognise dates
6
+ require 'chronic'
7
7
  Heuristics.define(:field_tester) do
8
8
  assume_default :integer
9
-
10
- assume(:string) { condition { value.instance_of? String } }
11
- assume(:hash) { condition { value.instance_of? Hash } }
12
- assume(:date) { condition { Chronic.parse(value) != nil } }
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
 
@@ -1,3 +1,3 @@
1
1
  module Heuristics
2
- VERSION = "0.0.3"
2
+ VERSION = "1.0.0"
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: heuristics
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.3
5
+ version: 1.0.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Peter Haza