Class: Typesafe::Score

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

Overview

A question that positions the state along an ordered spectrum of levels. The answer includes the score, the legend (levels by number), the probability distribution across levels, and a confidence.

Typesafe::Score.new("How frustrated is the customer?",
                  criteria: [
                    "Calm, just stating facts",
                    "Frustrated but civil",
                    "Very angry, strong language"
                  ])

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:) ⇒ Score

Returns a new instance of Score.

Parameters:

  • instructions (String)

    the question asked about the state.

  • criteria (Array<String>)

    the ordered levels; a non-empty array of non-empty Strings, ordered from lowest to highest.



21
22
23
24
# File 'lib/typesafe/score.rb', line 21

def initialize(instructions, criteria:)
  @criteria = normalize_criteria(criteria)
  super(instructions)
end

Instance Attribute Details

#criteriaArray<String> (readonly)

Returns the ordered levels of the spectrum.

Returns:

  • (Array<String>)

    the ordered levels of the spectrum.



16
17
18
# File 'lib/typesafe/score.rb', line 16

def criteria
  @criteria
end

Instance Method Details

#to_hObject



30
31
32
# File 'lib/typesafe/score.rb', line 30

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

#typeObject



26
27
28
# File 'lib/typesafe/score.rb', line 26

def type
  "score"
end