Class: Typesafe::Noul

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

Overview

A yes/no question. The answer is the probability that the answer is yes.

Typesafe::Noul.new("Does the customer request a refund?")

criteria optionally clarifies what yes and no mean:

Typesafe::Noul.new("Is the message urgent?",
                 criteria: { true: "Conveys urgency", false: "No time pressure" })

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: nil) ⇒ Noul

Returns a new instance of Noul.

Parameters:

  • instructions (String)

    the yes/no question asked about the state.

  • criteria (Hash, nil) (defaults to: nil)

    optional { true:, false: } descriptions of what yes and no mean. Keys may be Strings or Symbols and are normalized to Symbols.



20
21
22
23
# File 'lib/typesafe/noul.rb', line 20

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

Instance Attribute Details

#criteriaHash? (readonly)

Returns the optional { true:, false: } descriptions.

Returns:

  • (Hash, nil)

    the optional { true:, false: } descriptions.



14
15
16
# File 'lib/typesafe/noul.rb', line 14

def criteria
  @criteria
end

Instance Method Details

#to_hHash

Returns the API shape; criteria is omitted when not given.

Returns:

  • (Hash)

    the API shape; criteria is omitted when not given.



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

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

#typeObject



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

def type
  "noul"
end