README.md in diff_matcher-1.0.1 vs README.md in diff_matcher-2.0.0

- old
+ new

@@ -1,22 +1,37 @@ DiffMatcher === [![build status](http://travis-ci.org/playup/diff_matcher.png)](http://travis-ci.org/playup/diff_matcher) +[![still maintained](http://stillmaintained.com/playupchris/diff_matcher.png)](http://stillmaintained.com/playupchris/diff_matcher) Generates a diff by matching against expected values, classes, regexes and/or procs. DiffMatcher performs recursive matches on values contained in hashes, arrays and combinations thereof. Values in a containing object match when: - - actual == expected - - actual.is_a? expected # when expected is a class - - expected.match actual # when expected is a regexp - - expected.call actual # when expected is a proc +``` ruby +actual.is_a? expected # when expected is a class +expected.match actual # when expected is a regexp +expected.call actual # when expected is a proc +actual == expected # when expected is anything else +``` +Example: +``` ruby + puts DiffMatcher::difference( + { :a=>{ :a1=>11 }, :b=>[ 21, 22 ], :c=>/\d/, :d=>Fixnum, :e=>lambda { |x| (4..6).include? x } }, + { :a=>{ :a1=>10, :a2=>12 }, :b=>[ 21 ], :c=>'3' , :d=>4 , :e=>5 }, + :color_scheme=>:white_background + ) +``` + +![example output](https://raw.github.com/playup/diff_matcher/master/doc/diff_matcher.gif) + + Installation --- gem install diff_matcher @@ -82,11 +97,11 @@ ``` ruby puts DiffMatcher::difference([1], [1, 2]) # => [ # => + 2 # => ] -# => Where, - 1 additional +# => Where, + 1 additional ``` ### Options `:ignore_additional=>true` will match even if `actual` has additional items @@ -94,44 +109,32 @@ ``` ruby p DiffMatcher::difference([1], [1, 2], :ignore_additional=>true) # => nil ``` -`:verbose=>true` shows only missing and additional items in the output +`:quiet=>true` shows only missing and additional items in the output ``` ruby puts DiffMatcher::difference([Fixnum, 2], [1], :quiet=>true) # => [ # => - 2 # => ] # => Where, - 1 missing ``` -`:verbose=>true` shows all matched items in the output - -``` ruby -puts DiffMatcher::difference([Fixnum, 2], [1], :verbose=>true) -# => [ -# = > : 1, -# => - 2 -# => ] -# => Where, - 1 missing, : 1 match_class -``` - #### Prefixes -NB. The `: 1` from above includes a `:` prefix that shows the `1` was matched against a class (ie. `Fixnum`) - The items shown in a difference are prefixed as follows: missing => "- " additional => "+ " match value => match regexp => "~ " match class => ": " match proc => "{ " + #### Colours Colours (defined in colour schemes) can also appear in the difference. Using the `:default` colour scheme items shown in a difference are coloured as follows: @@ -141,22 +144,12 @@ match value => match regexp => green match class => blue match proc => cyan +Other colour schemes, eg. `:color_scheme=>:white_background` will use different colour mappings. -`:color_scheme=>:white_background` shows difference as follows - -``` ruby - puts DiffMatcher::difference( - { :a=>{ :a1=>11 }, :b=>[ 21, 22 ], :c=>/\d/, :d=>Fixnum, :e=>lambda { |x| (4..6).includes? x }, - { :a=>{ :a1=>10, :a2=>12 }, :b=>[ 21 ], :c=>'3' , :d=>4 , :e=>5 }, - :verbose=>true, :color_scheme=>:white_background - ) -``` - -![example output](https://raw.github.com/playup/diff_matcher/master/doc/example_output.png) - + Similar gems --- ### String differs