module Hashdiff
Extended Modules
Defined in:
hashdiff.crhashdiff/lcs.cr
hashdiff/linear_compare_arrays.cr
hashdiff/util.cr
version.cr
Constant Summary
-
Log =
::Log.for("hashdiff")
-
VERSION =
"1.0.2"
Instance Method Summary
-
#best_diff(obj1, obj2, **options)
Best diff two objects, which tries to generate the smallest change set using different similarity values.
-
#comparable?(obj1 : T, obj2 : L, strict = true) : Bool forall T, L
check if objects are comparable
-
#compare_values(obj1 : Number, obj2 : Number, **options) : Bool
check for equality or "closeness" within given tolerance
-
#compare_values(obj1 : String, obj2 : String, **options) : Bool
check for equality or "closeness" within given tolerance
-
#compare_values(obj1 : T, obj2 : L, **options) : Bool forall T, L
check for equality or "closeness" within given tolerance
-
#count_diff(diffs)
count node differences
-
#count_nodes(obj)
count total nodes for an object
-
#decode_property_path(path, delimiter = '.')
decode property path into an array [String] path Property-string [String] delimiter Property-string delimiter
- #diff(obj1 : NamedTuple, obj2 : NamedTuple, **options)
-
#diff(obj1 : T, obj2 : L, **options) forall T, L
ameba:disable Metrics/CyclomaticComplexity
-
#diff_array_lcs(arraya, arrayb, **options, &)
diff array using LCS algorithm
-
#lcs(arraya, arrayb, **options) : Array(Tuple(Int32, Int32))
caculate array difference using LCS algorithm http://en.wikipedia.org/wiki/Longest_common_subsequence_problem ameba:disable Metrics/CyclomaticComplexity
-
#node(hash : Hash(K, V), parts : Array(W)) forall K, V, W
get the node of hash by given path parts
- #prefix_append_array_index(prefix : Array(T), array_index : V, **opts) forall T, V
- #prefix_append_array_index(prefix : String, array_index, **opts)
- #prefix_append_key(key : V, prefix : Array(T), **opts) forall T, V
- #prefix_append_key(key, prefix : String, **opts)
-
#similar?(obja, objb, **options) : Bool
judge whether two objects are similar
Instance Method Detail
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