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 CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 1b76b901f0b2255c7730319703d9a513611046b0
4
- data.tar.gz: 96d566af4c8ec0ae6ca33524559e3c108ec86656
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NzRhMjNjMjJlMDRmMzk4MjM1ZWIxMTlkMmM5MjU0NjAyZDQ2MjdjNg==
5
+ data.tar.gz: !binary |-
6
+ MzdlMDAxNTk0ZjA4ODNhOWIxNjdiYThhYjNlYjhkODJiYTlhYWJiMQ==
5
7
  SHA512:
6
- metadata.gz: 481dbbcd00e83a73be568c435b6063c13ef4b089727624b6b188711fa79d857828ac845cd37436ef351b4366d8b245c9a3e9f392942c927fc02a98da58a1ffd4
7
- data.tar.gz: ebc3b5997305815617bf8468a918c4f18320c5e5619d923e6674220bc42ca6128b2313db56f28d8458cd32800b60b388aa4803294b9a6d7dcde68a1ada6f7a6b
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 five options available: `:delimiter`, `:similarity`, `:strict`, `:numeric_tolerance` and `:strip`.
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.
@@ -1,5 +1,9 @@
1
1
  # Change Log
2
2
 
3
+ ## v0.3.0 2016-2-11
4
+
5
+ * support `:case_insensitive` option
6
+
3
7
  ## v0.2.3 2015-11-5
4
8
 
5
9
  * improve performance of LCS algorithm #12
@@ -90,9 +90,13 @@ module HashDiff
90
90
  end
91
91
 
92
92
  if options[:strip] == true
93
- first = obj1.strip if obj1.respond_to?(:strip)
94
- second = obj2.strip if obj2.respond_to?(:strip)
95
- return first == second
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
@@ -1,3 +1,3 @@
1
1
  module HashDiff
2
- VERSION = '0.2.3'
2
+ VERSION = '0.3.0'
3
3
  end
@@ -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'} }
@@ -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.2.3
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: 2015-11-05 00:00:00.000000000 Z
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 two
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.0.14
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: