Class: Philiprehberger::Approx::RSpecMatchers::BeApproxWithinMatcher Private

Inherits:
Object
  • Object
show all
Defined in:
lib/philiprehberger/approx/rspec_matchers.rb

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

Instance Method Summary collapse

Constructor Details

#initialize(expected, abs, rel, percent) ⇒ BeApproxWithinMatcher

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 a new instance of BeApproxWithinMatcher.



65
66
67
68
69
70
# File 'lib/philiprehberger/approx/rspec_matchers.rb', line 65

def initialize(expected, abs, rel, percent)
  @expected = expected
  @abs = abs
  @rel = rel
  @percent = percent
end

Instance Method Details

#descriptionObject

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.



82
83
84
# File 'lib/philiprehberger/approx/rspec_matchers.rb', line 82

def description
  "be approximately equal to #{@expected.inspect} (#{tolerance_description})"
end

#failure_messageObject

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.



86
87
88
# File 'lib/philiprehberger/approx/rspec_matchers.rb', line 86

def failure_message
  "expected #{@actual.inspect} to be approximately equal to #{@expected.inspect} (#{tolerance_description})"
end

#failure_message_when_negatedObject

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.



90
91
92
# File 'lib/philiprehberger/approx/rspec_matchers.rb', line 90

def failure_message_when_negated
  "expected #{@actual.inspect} not to be approximately equal to #{@expected.inspect} (#{tolerance_description})"
end

#matches?(actual) ⇒ 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:

  • (Boolean)


72
73
74
75
76
77
78
79
80
# File 'lib/philiprehberger/approx/rspec_matchers.rb', line 72

def matches?(actual)
  @actual = actual

  if @percent
    Approx.percent_equal?(actual, @expected, percent: @percent)
  else
    Approx.within?(actual, @expected, abs: @abs, rel: @rel)
  end
end