Class: HashesEqual::HashRoundedDiffDisplayer

Inherits:
HashDiffDisplayer show all
Defined in:
lib/hashes_equal/hash_rounded_diff_displayer.rb

Defined Under Namespace

Classes: PrecisionMustBeNonNegativeInteger

Instance Method Summary collapse

Methods inherited from GenericDiffDisplayer

#call, #diff

Constructor Details

#initialize(expected:, actual:, precision:) ⇒ HashRoundedDiffDisplayer

Returns a new instance of HashRoundedDiffDisplayer.



9
10
11
12
13
14
15
16
17
# File 'lib/hashes_equal/hash_rounded_diff_displayer.rb', line 9

def initialize(expected:, actual:, precision:)
  @precision = precision

  super(expected: expected, actual: actual) do |_path, left, right|
    next unless left.is_a?(Numeric) && right.is_a?(Numeric)

    left.round(precision) == right.round(precision)
  end
end