Class: Typesafe::NoulAnswer

Inherits:
Answer
  • Object
show all
Defined in:
lib/typesafe/noul_answer.rb

Overview

The answer to a Noul question: the yes/no probability on a scale from 0 (no) to 1 (yes).

Typesafe::NoulAnswer.new(noul: 0.95)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Answer

#==, #hash, #to_json

Constructor Details

#initialize(noul:) ⇒ NoulAnswer

Returns a new instance of NoulAnswer.

Parameters:

  • noul (Numeric)

    the yes/no probability, between 0 and 1.

Raises:

  • (ArgumentError)

    if noul is not a Numeric between 0 and 1.



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

def initialize(noul:)
  @noul = validate_probability(noul, "noul")
  freeze
end

Instance Attribute Details

#noulNumeric (readonly)

Returns the yes/no answer, between 0 (no) and 1 (yes).

Returns:

  • (Numeric)

    the yes/no answer, between 0 (no) and 1 (yes).



10
11
12
# File 'lib/typesafe/noul_answer.rb', line 10

def noul
  @noul
end

Class Method Details

.from_h(hash) ⇒ NoulAnswer

Parameters:

  • hash (Hash)

    a noul answer entry from the API response, with String or Symbol keys.

Returns:



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

def self.from_h(hash)
  new(noul: hash["noul"] || hash[:noul])
end

Instance Method Details

#to_hObject



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

def to_h
  { type: type, noul: noul }
end

#typeObject



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

def type
  "noul"
end