README.md in hashdiff-0.0.3 vs README.md in hashdiff-0.0.4

- old
+ new

@@ -1,38 +1,49 @@ -HashDiff -========= +# HashDiff +[![Build Status](https://secure.travis-ci.org/liufengyun/hashdiff.png)](http://travis-ci.org/liufengyun/hashdiff) + HashDiff is a ruby library to compute the smallest difference between two hashes. -Requirements ------------- -HashDiff is tested on following platforms: +**Demo**: [HashDiff](http://hashdiff.herokuapp.com/) -- 1.8.7 -- 1.9.2 -- 1.9.3 -- rbx -- rbx-2.0 -- ree -- jruby -- ruby-head +**Docs**: [Documentation](http://rubydoc.info/gems/hashdiff) -Usage ------------- -If you're using bundler, add following: +## Why HashDiff? +Given two Hashes A and B, sometimes you face the question: what's the smallest changes that can be made to change A to B? + +An algorithm responds to this question has to do following: + +* Generate a list of additions, deletions and changes, so that `A + ChangeSet = B` and `B - ChangeSet = A`. +* Compute recursively -- Arrays and Hashes may be nested arbitrarily in A or B. +* Compute the smallest change -- it should recoganize similar child Hashes or child Arrays between A and B. + +HashDiff answers the question above in an opinionated approach: + +* Hash can be represented as a list of (dot-syntax-path, value) pairs. For example, `{a:[{c:2}]}` can be represented as `["a[0].c", 2]`. +* The change set can be represented using the do-syntax representation. For example, `[['-', 'b.x', 3], ['~', 'b.z', 45, 30], ['+', 'b.y', 3]]`. +* It compares Arrays using LCS(longest common subsequence) algorithm. +* It recoganize similar Hashes in Array using a similarity value(0 < similarity <= 1). + + +## Compatibility + +HashDiff is tested against `1.9.2`, `1.9.3` and `ruby-head`. It should work on other versions as well. + +## Usage + +If you're using bundler, add following to the Gemfile: + gem 'hashdiff' Or, you can run `gem install hashdiff`, then add following line to your ruby file which uses HashDiff: require 'hashdiff' -Quick Start ------------ +## Quick Start -You can find full docs here: [Documentation](http://rubydoc.info/gems/hashdiff) - ### Diff Two simple hash: a = {a:3, b:2} @@ -63,21 +74,20 @@ a = {a: 3} b = {a: {a1: 1, a2: 2}} diff = HashDiff.diff(a, b) - HashDiff.patch(a, diff).should == b + HashDiff.patch!(a, diff).should == b unpatch example: a = [{a: 1, b: 2, c: 3, d: 4, e: 5}, {x: 5, y: 6, z: 3}, 1] b = [1, {a: 1, b: 2, c: 3, e: 5}] diff = HashDiff.diff(a, b) # diff two array is OK - HashDiff.unpatch(b, diff).should == a + HashDiff.unpatch!(b, diff).should == a -License -------- +## License HashDiff is distributed under the MIT-LICENSE.