Class: Typesafe::Choice

Inherits:
Question show all
Defined in:
lib/typesafe/choice.rb

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

Attributes inherited from Question

#instructions

Instance Method Summary collapse

Methods inherited from Question

#==, #hash, #to_json

Constructor Details

#initialize(instructions, criteria:) ⇒ Choice

Returns a new instance of Choice.

Parameters:

  • instructions (String)

    the question asked about the state.

  • criteria (Hash)

    the options: keys (String or Symbol) mapped to non-empty String descriptions.



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

#criteriaHash (readonly)

Returns the option keys mapped to their descriptions.

Returns:

  • (Hash)

    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_hObject



29
30
31
# File 'lib/typesafe/choice.rb', line 29

def to_h
  super.merge(criteria: @criteria)
end

#typeObject



25
26
27
# File 'lib/typesafe/choice.rb', line 25

def type
  "choice"
end