Class: Matchi::BeWithin
- Inherits:
-
Object
- Object
- Matchi::BeWithin
- Defined in:
- lib/matchi/be_within.rb
Overview
Delta comparison matcher that checks if a numeric value is within a specified range.
This matcher verifies that a numeric value falls within a certain distance (delta) of an expected value. It’s particularly useful for floating-point comparisons or when checking if a value is approximately equal to another within a given tolerance.
Defined Under Namespace
Classes: Of
Instance Method Summary collapse
-
#initialize(delta) ⇒ BeWithin
constructor
Initialize the matcher with a delta value.
-
#match? ⇒ Boolean
Raises NotImplementedError as this is not a complete matcher.
-
#of(expected) ⇒ #match?
Specifies the expected reference value.
Constructor Details
#initialize(delta) ⇒ BeWithin
Initialize the matcher with a delta value.
45 46 47 48 49 50 |
# File 'lib/matchi/be_within.rb', line 45 def initialize(delta) raise ::ArgumentError, "delta must be a Numeric" unless delta.is_a?(::Numeric) raise ::ArgumentError, "delta must be non-negative" if delta.negative? @delta = delta end |
Instance Method Details
#match? ⇒ Boolean
Raises NotImplementedError as this is not a complete matcher.
This class acts as a builder for the actual matcher, which is created by calling the #of method. Direct use of #match? is not supported.
67 68 69 |
# File 'lib/matchi/be_within.rb', line 67 def match? raise ::NotImplementedError, "BeWithin is not a complete matcher. Use BeWithin#of to create a valid matcher." end |