liufengyun/hashdiff — pull request #3 by ravigadad (2014-03-16 03:28:26+00:00)
Title: Add :tolerance option for "close" numeric value comparisons

Thank you for this library - it has been very helpful!

We create a lot of hashes containing financial calculations, such as payment schedules and lists of fees. Comparing these is difficult because sometimes the calculations result in very precise numbers (like 452.382241), and we only care that the result within a given tolerance (such as 0.001). For example:

```ruby
a = {x:5, y:3.75, z:7, w:[3, 4.45]}
b = {x:6, y:3.76, z:7, w:[3, 4.47]}

# without :tolerance, numbers are compared exactly
diff = HashDiff.diff(a, b)
diff.should == [["~", "x", 5, 6], ["~", "y", 3.75, 3.76], ["-", "w[1]", 4.45], ["+", "w[1]", 4.47]]

# the :tolerance option allows for a small numeric tolerance
diff = HashDiff.diff(a, b, :tolerance => 0.1)
diff.should == [["~", "x", 5, 6]]
```

I've added this functionality. By default, everything works as it did before - numbers are compared exactly. Numeric comparisons are changed only when the `:tolerance` option is provided. Therefore, this will not break any existing implementations, but adds extra functionality when desired.

I updated the documentation for the new functionality, and also did some minor clean-up of the existing documentation.