heuristics 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -66,7 +66,12 @@ Or install it yourself as:
66
66
  # First assumption to test true for all conditions will win
67
67
  # Returns :hash_with_values in this case
68
68
  Heuristics.test(:field_tester, {a: 1})
69
-
69
+
70
+
71
+ NOTE:
72
+ Order matters. First assumption to return true for all conditions will be used.
73
+ This means you should write your assumptions in the order from most specific to least specfic.
74
+
70
75
  ## Contributing
71
76
 
72
77
  1. Fork it
@@ -1,3 +1,3 @@
1
1
  module Heuristics
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -33,6 +33,21 @@ describe Heuristics do
33
33
  Heuristics.test(:external_lib_test, '23.09.85').must_equal :date
34
34
  end
35
35
 
36
+ it 'should return the assumption that first matched all conditions' do
37
+ require 'chronic'
38
+ Heuristics.define(:first_come_first_serve) do
39
+ assume_default nil # This is implicit anyway
40
+
41
+ assume(:date) { condition { Chronic.parse(value) != nil } }
42
+ assume(:integer_string) { condition { value =~ /\A\d+\Z/ } }
43
+ assume(:string) { condition { value.instance_of? String } }
44
+ end
45
+
46
+ Heuristics.test(:first_come_first_serve, '23.09.85').must_equal :date
47
+ Heuristics.test(:first_come_first_serve, '27').must_equal :integer_string
48
+ Heuristics.test(:first_come_first_serve, 'This is string').must_equal :string
49
+ end
50
+
36
51
  it 'should return default if no assumptions are true' do
37
52
  Heuristics.define(:default_test) { assume_default :string; assume(:email) { condition { false } } }
38
53
  Heuristics.test(:default_test, 1).must_equal :string
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: heuristics
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.0.0
5
+ version: 1.0.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Peter Haza