hunch 0.1.0 → 0.2.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.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/lib/hunch/decision.rb +27 -3
- data/lib/hunch/version.rb +1 -1
- data/lib/hunch.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a696037fbdde4271f78d6791bf6cc78bb63a40eff67826a95c2824bcc6a11b09
|
|
4
|
+
data.tar.gz: 62156178770fd54095e2305b75589fec4912a16be951128dcad6f0b240a63014
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9a893724840f3e4eeef9fafcbd5ccacff3ed94496d7c4043e6b78a730f4026df44ff4bf71b37cba09ad977de4eba98192cc01a631ffc9c0c9c5a806e633793c4
|
|
7
|
+
data.tar.gz: 93d6892320b259b9021dd8c3f97552d3ea0b06778350c415122f38565bb4904e0d5184a89928f1091e4f82cdbe482a4081bc772af752719805c0080ecaf3dbf9
|
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.
|
|
81
|
-
q.pick
|
|
82
|
-
q.rate
|
|
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
|
data/lib/hunch/decision.rb
CHANGED
|
@@ -6,9 +6,10 @@ module Hunch
|
|
|
6
6
|
@questions = {}
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
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
|
|