Hashdiff
Constants
Instance methods
Best diff two objects, which tries to generate the smallest change set using different similarity values.
Hashdiff.best_diff is useful in case of comparing two objects which include similar hashes in arrays.
The options to use when comparing
- :strict (Boolean) [true] whether numeric values will be compared on type as well as value. Set to false to allow comparing Integer, Float, BigDecimal to each other
- :indifferent (Boolean) [false] whether to treat hash keys indifferently. Set to true to ignore differences between symbol keys (ie. {a: 1} ~= {'a' => 1})
- :delimiter (String) ['.'] the delimiter used when returning nested key references
- :numeric_tolerance (Numeric) [0] should be a positive numeric value. Value by which numeric differences must be greater than. By default, numeric values are compared exactly; with the :tolerance option, the difference between numeric values must be greater than the given value.
- :strip (Boolean) [false] whether or not to call #strip on strings before comparing
- :array_path (Boolean) [false] whether to return the path references for nested values in an array, can be used for patch compatibility with non string keys.
- :use_lcs (Boolean) [true] whether or not to use an implementation of the Longest common subsequence algorithm for comparing arrays, produces better diffs but is slower.
returns an array of change tuples. e.g. [{ '+', 'a.b', '45' }, { '-', 'a.c', '5' }, { '~', 'a.x', '45', '63 }']
a = {'x' => [{'a' => 1, 'c' => 3, 'e' => 5}, {'y' => 3}]}
b = {'x' => [{'a' => 1, 'b' => 2, 'e' => 5}] }
diff = Hashdiff.best_diff(a, b)
diff.should == [{'-', 'x[0].c', 3}, {'+', 'x[0].b', 2}, {'-', 'x[1].y', 3}, {'-', 'x[1]', {}}]
check if objects are comparable
check for equality or "closeness" within given tolerance
check for equality or "closeness" within given tolerance
check for equality or "closeness" within given tolerance
decode property path into an array [String] path Property-string [String] delimiter Property-string delimiter
e.g. "a.b[3].c" => ['a', 'b', 3, 'c']
caculate array difference using LCS algorithm http://en.wikipedia.org/wiki/Longest_common_subsequence_problem ameba:disable Metrics/CyclomaticComplexity
get the node of hash by given path parts