Class: Typesafe::Choice
Overview
A question that selects one option from a defined, unordered set. The answer includes the selected option, the probability distribution across all options, and a confidence.
Typesafe::Choice.new("Which team should handle this?",
criteria: {
billing: "Payment or subscription issues",
technical: "Bugs or integration problems"
})
Instance Attribute Summary collapse
-
#criteria ⇒ Hash
readonly
The option keys mapped to their descriptions.
Attributes inherited from Question
Instance Method Summary collapse
-
#initialize(instructions, criteria:) ⇒ Choice
constructor
A new instance of Choice.
- #to_h ⇒ Object
- #type ⇒ Object
Methods inherited from Question
Constructor Details
#initialize(instructions, criteria:) ⇒ Choice
Returns a new instance of Choice.
20 21 22 23 |
# File 'lib/typesafe/choice.rb', line 20 def initialize(instructions, criteria:) @criteria = normalize_criteria(criteria) super(instructions) end |
Instance Attribute Details
#criteria ⇒ Hash (readonly)
Returns the option keys mapped to their descriptions.
15 16 17 |
# File 'lib/typesafe/choice.rb', line 15 def criteria @criteria end |
Instance Method Details
#to_h ⇒ Object
29 30 31 |
# File 'lib/typesafe/choice.rb', line 29 def to_h super.merge(criteria: @criteria) end |
#type ⇒ Object
25 26 27 |
# File 'lib/typesafe/choice.rb', line 25 def type "choice" end |