hunch 0.1.0 → 0.2.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4fe18b2f4a16d13a14ca5ff3c9887404e1ebc0b455e66b9c151951efc27c5fae
4
- data.tar.gz: 638b1ee2b57368e9acd352f2fe06bfb6beafc89e29f93b42de1026cc5160c8c7
3
+ metadata.gz: d5212609eafab9be2c8813b1a0b32f0b651f95e270cc1ff1dcd9e6d87f1ed5dd
4
+ data.tar.gz: 2363dfd04ef0d8e867d2dcd4b2c1c5cafa52bfa06a9daa70e49af599cf4dea02
5
5
  SHA512:
6
- metadata.gz: 95b72749b648e44622a5e414fe3f9e6c6df1d8926072e324f20802f1223e86382b1130e647038b256ecd9290558491976a9d8c5da593882ca86d789580728e42
7
- data.tar.gz: 36256933743330d1b84d04b2b296fa8d758a90a24ea89c4ba50c373190eadb806553a6587734bcdc0c0b6da69eadfcf4d81e04c1108a964466339d8202012eef
6
+ metadata.gz: 7a1d80b8796f2cc338a6c9737d3cd90f9be59765cca481541e90c08fec9978edcff8c8d0a959c01874f097f47d9509fe6afaa78e564aec51510596fa8457e406
7
+ data.tar.gz: aee0298254221750897e39eece6c4ccf5cb2de8249277be21feef204d82fa63de56aacf6de554c403c52367c0edd21ea059a182ad6480c4a041a9a4143519328
data/README.md CHANGED
@@ -77,9 +77,9 @@ Several questions about one piece of state cost one API call:
77
77
 
78
78
  ```ruby
79
79
  result = Hunch.decide(given: mail.raw_source) do |q|
80
- q.likely? :urgent, "does this convey urgency?", over: :probable
81
- q.pick :team, billing: "payments", technical: "bugs", sales: "pricing"
82
- q.rate :mood, :calm, :frustrated, :livid
80
+ q.probable? :urgent, "does this convey urgency?"
81
+ q.pick :team, billing: "payments", technical: "bugs", sales: "pricing"
82
+ q.rate :mood, :calm, :frustrated, :livid
83
83
  end
84
84
 
85
85
  result.urgent # => 0.92
@@ -6,9 +6,10 @@ module Hunch
6
6
  @questions = {}
7
7
  end
8
8
 
9
- def likely?(key, question, yes: nil, no: nil, over: 0.5)
10
- threshold = Hunch.configuration.resolve_level(over)
11
- add Questions::Noul.new(key: key.to_sym, question:, yes:, no:, threshold:)
9
+ Configuration::LEVELS.each_key do |level|
10
+ define_method(:"#{level}?") do |key, question, yes: nil, no: nil|
11
+ noul(key, question, yes:, no:, threshold: Hunch.configuration.levels.fetch(level))
12
+ end
12
13
  end
13
14
 
14
15
  def pick(key, *options, question: nil, **described)
@@ -27,6 +28,29 @@ module Hunch
27
28
 
28
29
  private
29
30
 
31
+ def custom_level(name)
32
+ return unless name.to_s.end_with?("?")
33
+
34
+ level = name.to_s.delete_suffix("?").to_sym
35
+ Hunch.configuration.levels.key?(level) ? level : nil
36
+ end
37
+
38
+ def method_missing(name, *args, **options)
39
+ level = custom_level(name)
40
+ return super unless level
41
+
42
+ key, question = args
43
+ noul(key, question, **options, threshold: Hunch.configuration.levels.fetch(level))
44
+ end
45
+
46
+ def respond_to_missing?(name, include_private = false)
47
+ !custom_level(name).nil? || super
48
+ end
49
+
50
+ def noul(key, question, yes: nil, no: nil, threshold:)
51
+ add Questions::Noul.new(key: key.to_sym, question:, yes:, no:, threshold:)
52
+ end
53
+
30
54
  def describe(bare, described)
31
55
  bare.to_h { |name| [name.to_sym, name.to_s.tr("_", " ")] }.merge(described)
32
56
  end
data/lib/hunch/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Hunch
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.1"
3
3
  end
data/lib/hunch.rb CHANGED
@@ -2,9 +2,9 @@ require_relative "hunch/version"
2
2
  require_relative "hunch/errors"
3
3
  require_relative "hunch/questions"
4
4
  require_relative "hunch/rating"
5
+ require_relative "hunch/configuration"
5
6
  require_relative "hunch/decision"
6
7
  require_relative "hunch/result"
7
- require_relative "hunch/configuration"
8
8
  require_relative "hunch/backends/jev"
9
9
  require_relative "hunch/backends/stub"
10
10
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hunch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carl Dawson
@@ -9,7 +9,7 @@ bindir: bin
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies: []
12
- description: 'likely?, pick, and score: three primitives that let Ruby branch on judgment
12
+ description: 'chance, pick, and rate: three primitives that let Ruby branch on judgment
13
13
  calls, answered by TypeSafe''s Jev System One model or any backend you plug in.'
14
14
  email:
15
15
  - carldawson@hey.com