Class: Matchi::BeWithin::Of
- Inherits:
-
Object
- Object
- Matchi::BeWithin::Of
- Defined in:
- lib/matchi/be_within/of.rb
Overview
*BeWithin of* matcher.
Instance Attribute Summary collapse
-
#expected ⇒ Numeric
readonly
An expected value.
Instance Method Summary collapse
-
#initialize(delta, expected) ⇒ Of
constructor
Initialize the matcher with a delta and an expected value.
-
#inspect ⇒ Object
A string containing a human-readable representation of the matcher.
-
#matches? ⇒ Boolean
Boolean comparison on the expected be_within by comparing the actual value and the expected value.
-
#to_s ⇒ Object
Returns a string representing the matcher.
Constructor Details
#initialize(delta, expected) ⇒ Of
Initialize the matcher with a delta and an expected value.
19 20 21 22 |
# File 'lib/matchi/be_within/of.rb', line 19 def initialize(delta, expected) @delta = delta @expected = expected end |
Instance Attribute Details
#expected ⇒ Numeric (readonly)
Returns An expected value.
8 9 10 |
# File 'lib/matchi/be_within/of.rb', line 8 def expected @expected end |
Instance Method Details
#inspect ⇒ Object
A string containing a human-readable representation of the matcher.
43 44 45 |
# File 'lib/matchi/be_within/of.rb', line 43 def inspect "#{self.class}(#{@delta}, #{expected})" end |
#matches? ⇒ Boolean
Boolean comparison on the expected be_within by comparing the actual value and the expected value.
38 39 40 |
# File 'lib/matchi/be_within/of.rb', line 38 def matches? (expected - yield).abs <= @delta end |
#to_s ⇒ Object
Returns a string representing the matcher.
48 49 50 |
# File 'lib/matchi/be_within/of.rb', line 48 def to_s "be within #{@delta} of #{expected}" end |