hashdiff 0.2.3 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +13 -5
- data/README.md +14 -18
- data/changelog.md +4 -0
- data/lib/hashdiff/util.rb +7 -3
- data/lib/hashdiff/version.rb +1 -1
- data/spec/hashdiff/diff_spec.rb +25 -0
- data/spec/hashdiff/util_spec.rb +6 -1
- metadata +12 -11
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NzRhMjNjMjJlMDRmMzk4MjM1ZWIxMTlkMmM5MjU0NjAyZDQ2MjdjNg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MzdlMDAxNTk0ZjA4ODNhOWIxNjdiYThhYjNlYjhkODJiYTlhYWJiMQ==
|
5
7
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
OGE1NDRmNjA2MThmZDJlZDA1YmI2Nzg2YmQ0OTQyMzVlZGNiZDJiYWQ4Y2Y5
|
10
|
+
ODdiNDdkYTRlMjZkNWFmNTE5NmEzMjRhYTVjZGY5YTEzZjEyMDA1YmZlY2E2
|
11
|
+
ZWRiNjFiOTdiNGU4YzRkYTZhZjk0YjMxNWNmN2Q3ODg5MGY5YTU=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZWU1MDBjNTNkZTZjMTRiYzBhOTY2NGY1OGM4OWE0MjI1OGM4ZjM1YzFiMDVk
|
14
|
+
NGRkNzYxZjc1NzkzODEyMzk4OTgzOWQxMjg3Y2IxYjE3ZDE2ZTFjOGY3ZjJj
|
15
|
+
MGMxZDNiNDcyNTBmZjM3YWYxZjc4ZTMyNmE4MTAxYTk0NTJlYWQ=
|
data/README.md
CHANGED
@@ -87,7 +87,8 @@ HashDiff.unpatch!(b, diff).should == a
|
|
87
87
|
|
88
88
|
### Options
|
89
89
|
|
90
|
-
There are
|
90
|
+
There are six options available: `:delimiter`, `:similarity`,
|
91
|
+
`:strict`, `:numeric_tolerance`, `:strip` and `:case_insensitive`.
|
91
92
|
|
92
93
|
#### `:delimiter`
|
93
94
|
|
@@ -133,6 +134,18 @@ diff = HashDiff.diff(a, b, :comparison => { :numeric_tolerance => 0.1, :strip =>
|
|
133
134
|
diff.should == [["~", "x", 5, 6]]
|
134
135
|
```
|
135
136
|
|
137
|
+
#### `:case_insensitive`
|
138
|
+
|
139
|
+
The :case_insensitive option makes string comparisions ignore case.
|
140
|
+
|
141
|
+
```ruby
|
142
|
+
a = {x:5, s:'FooBar'}
|
143
|
+
b = {x:6, s:'foobar'}
|
144
|
+
|
145
|
+
diff = HashDiff.diff(a, b, :comparison => { :numeric_tolerance => 0.1, :case_insensitive => true })
|
146
|
+
diff.should == [["~", "x", 5, 6]]
|
147
|
+
```
|
148
|
+
|
136
149
|
#### Specifying a custom comparison method
|
137
150
|
|
138
151
|
It's possible to specify how the values of a key should be compared.
|
@@ -184,23 +197,6 @@ b[:b].sort!
|
|
184
197
|
HashDiff.diff(a, b) => []
|
185
198
|
```
|
186
199
|
|
187
|
-
### Special use cases
|
188
|
-
|
189
|
-
#### Using HashDiff on JSON API results
|
190
|
-
|
191
|
-
```ruby
|
192
|
-
require 'uri'
|
193
|
-
require 'net/http'
|
194
|
-
require 'json'
|
195
|
-
|
196
|
-
uri = URI('http://time.jsontest.com/')
|
197
|
-
json_resp = ->(uri) { JSON.parse(Net::HTTP.get_response(uri).body) }
|
198
|
-
a = json_resp.call(uri)
|
199
|
-
b = json_resp.call(uri)
|
200
|
-
|
201
|
-
HashDiff.diff(a,b) => [["~", "milliseconds_since_epoch", 1410542545874, 1410542545985]]
|
202
|
-
```
|
203
|
-
|
204
200
|
## License
|
205
201
|
|
206
202
|
HashDiff is distributed under the MIT-LICENSE.
|
data/changelog.md
CHANGED
data/lib/hashdiff/util.rb
CHANGED
@@ -90,9 +90,13 @@ module HashDiff
|
|
90
90
|
end
|
91
91
|
|
92
92
|
if options[:strip] == true
|
93
|
-
|
94
|
-
|
95
|
-
|
93
|
+
obj1 = obj1.strip if obj1.respond_to?(:strip)
|
94
|
+
obj2 = obj2.strip if obj2.respond_to?(:strip)
|
95
|
+
end
|
96
|
+
|
97
|
+
if options[:case_insensitive] == true
|
98
|
+
obj1 = obj1.downcase if obj1.respond_to?(:downcase)
|
99
|
+
obj2 = obj2.downcase if obj2.respond_to?(:downcase)
|
96
100
|
end
|
97
101
|
|
98
102
|
obj1 == obj2
|
data/lib/hashdiff/version.rb
CHANGED
data/spec/hashdiff/diff_spec.rb
CHANGED
@@ -183,6 +183,22 @@ describe HashDiff do
|
|
183
183
|
end
|
184
184
|
end
|
185
185
|
|
186
|
+
context 'when :case_insensitive requested' do
|
187
|
+
it "should strip strings before comparing" do
|
188
|
+
a = { 'a' => "Foo", 'b' => "fizz buzz"}
|
189
|
+
b = { 'a' => "foo", 'b' => "fizzBuzz"}
|
190
|
+
diff = HashDiff.diff(a, b, :case_insensitive => true)
|
191
|
+
diff.should == [['~', 'b', "fizz buzz", "fizzBuzz"]]
|
192
|
+
end
|
193
|
+
|
194
|
+
it "should ignore case on nested strings before comparing" do
|
195
|
+
a = { 'a' => { 'x' => "Foo" }, 'b' => ["fizz buzz", "nerf"] }
|
196
|
+
b = { 'a' => { 'x' => "foo" }, 'b' => ["fizzbuzz", "nerf"] }
|
197
|
+
diff = HashDiff.diff(a, b, :case_insensitive => true)
|
198
|
+
diff.should == [['-', 'b[0]', "fizz buzz"], ['+', 'b[0]', "fizzbuzz"]]
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
186
202
|
context 'when both :strip and :numeric_tolerance requested' do
|
187
203
|
it 'should apply filters to proper object types' do
|
188
204
|
a = { 'a' => " foo", 'b' => 35, 'c' => 'bar', 'd' => 'baz' }
|
@@ -192,6 +208,15 @@ describe HashDiff do
|
|
192
208
|
end
|
193
209
|
end
|
194
210
|
|
211
|
+
context "when both :strip and :case_insensitive requested" do
|
212
|
+
it "should apply both filters to strings" do
|
213
|
+
a = { 'a' => " Foo", 'b' => "fizz buzz"}
|
214
|
+
b = { 'a' => "foo", 'b' => "fizzBuzz"}
|
215
|
+
diff = HashDiff.diff(a, b, :case_insensitive => true, :strip => true)
|
216
|
+
diff.should == [['~', 'b', "fizz buzz", "fizzBuzz"]]
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
195
220
|
context 'with custom comparison' do
|
196
221
|
let(:a) { { 'a' => 'car', 'b' => 'boat', 'c' => 'plane'} }
|
197
222
|
let(:b) { { 'a' => 'bus', 'b' => 'truck', 'c' => ' plan'} }
|
data/spec/hashdiff/util_spec.rb
CHANGED
@@ -63,11 +63,16 @@ describe HashDiff do
|
|
63
63
|
|
64
64
|
it 'should compare strings exactly by default' do
|
65
65
|
expect(HashDiff.compare_values(' horse', 'horse')).to be_false
|
66
|
+
expect(HashDiff.compare_values('horse', 'Horse')).to be_false
|
66
67
|
end
|
67
68
|
|
68
69
|
it 'should strip strings before comparing when requested' do
|
69
70
|
expect(HashDiff.compare_values(' horse', 'horse', :strip => true)).to be_true
|
70
71
|
end
|
72
|
+
|
73
|
+
it "should ignore string case when requested" do
|
74
|
+
expect(HashDiff.compare_values('horse', 'Horse', :case_insensitive => true)).to be_true
|
75
|
+
end
|
76
|
+
|
71
77
|
end
|
72
78
|
end
|
73
|
-
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hashdiff
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Liu Fengyun
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -28,32 +28,32 @@ dependencies:
|
|
28
28
|
name: yard
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - '>='
|
31
|
+
- - ! '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - '>='
|
38
|
+
- - ! '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bluecloth
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - '>='
|
45
|
+
- - ! '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - '>='
|
52
|
+
- - ! '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
-
description: ' HashDiff is a diff lib to compute the smallest difference between
|
56
|
-
hashes. '
|
55
|
+
description: ! ' HashDiff is a diff lib to compute the smallest difference between
|
56
|
+
two hashes. '
|
57
57
|
email:
|
58
58
|
- liufengyunchina@gmail.com
|
59
59
|
executables: []
|
@@ -93,18 +93,19 @@ require_paths:
|
|
93
93
|
- lib
|
94
94
|
required_ruby_version: !ruby/object:Gem::Requirement
|
95
95
|
requirements:
|
96
|
-
- - '>='
|
96
|
+
- - ! '>='
|
97
97
|
- !ruby/object:Gem::Version
|
98
98
|
version: 1.8.7
|
99
99
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- - '>='
|
101
|
+
- - ! '>='
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: '0'
|
104
104
|
requirements: []
|
105
105
|
rubyforge_project:
|
106
|
-
rubygems_version: 2.
|
106
|
+
rubygems_version: 2.4.8
|
107
107
|
signing_key:
|
108
108
|
specification_version: 4
|
109
109
|
summary: HashDiff is a diff lib to compute the smallest difference between two hashes.
|
110
110
|
test_files: []
|
111
|
+
has_rdoc:
|