Module: Matchi::Number Private

Defined in:
lib/matchi/number.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Validation of the numbers given to matchers: deltas and expected values must be finite and real, so that a NaN, an infinity or a Complex cannot build a matcher that never, or always, passes.

Class Method Summary collapse

Class Method Details

.finite_real!(value, role) ⇒ Numeric

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns value.

Parameters:

  • value (Object)
  • role (String) —

    the argument name, for the error message

Returns:

  • (Numeric) —

    value

Raises:

  • (ArgumentError) —

    when value is not a finite real Numeric



20
21
22
23
24
# File 'lib/matchi/number.rb', line 20

def self.finite_real!(value, role)
  raise ::ArgumentError, "#{role} must be a finite real Numeric (got: #{value.inspect})" unless finite_real?(value)

  value
end

.finite_real?(value) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns whether value is a finite real Numeric.

Parameters:

  • value (Object)

Returns:

  • (Boolean) —

    whether value is a finite real Numeric



12
13
14
# File 'lib/matchi/number.rb', line 12

def self.finite_real?(value)
  ::Numeric === value && value.real? && value.finite?
end

.non_negative!(value, role) ⇒ Numeric

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns value.

Parameters:

  • value (Object)
  • role (String) —

    the argument name, for the error message

Returns:

  • (Numeric) —

    value

Raises:

  • (ArgumentError) —

    when value is not a finite real non-negative Numeric



30
31
32
33
34
35
# File 'lib/matchi/number.rb', line 30

def self.non_negative!(value, role)
  finite_real!(value, role)
  raise ::ArgumentError, "#{role} must be non-negative (got: #{value.inspect})" if value.negative?

  value
end