json-compare 0.1 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - rbx-18mode
7
+ - ree
data/README.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  Returns the difference between two JSON files.
4
4
 
5
+ [![Build Status](http://travis-ci.org/a2design-company/json-compare.png?branch=master)](http://travis-ci.org/a2design-company/json-compare)
6
+ [![Dependency Status](https://gemnasium.com/a2design-company/json-compare.png?travis)](https://gemnasium.com/a2design-company/json-compare)
7
+ [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/a2design-company/json-compare)
8
+
5
9
  ## Installation
6
10
 
7
11
  Add this line to your application's Gemfile:
data/Rakefile CHANGED
@@ -5,3 +5,5 @@ require 'rspec/core/rake_task'
5
5
  RSpec::Core::RakeTask.new(:spec) do |spec|
6
6
  spec.pattern = 'spec/**/*_spec.rb'
7
7
  end
8
+
9
+ task :default => :spec
data/TODO ADDED
@@ -0,0 +1,7 @@
1
+ - Add possibility for exclusion of some keys from the comparison,
2
+ or in other way to check only some keys
3
+ - Improve the code quality
4
+ - Make it workable for 1.8.7, rbx and ree
5
+ - Add documentation!
6
+ - Add more examples!!
7
+ - Add more specs!!!
@@ -22,23 +22,16 @@ module JsonCompare
22
22
  end
23
23
 
24
24
  def compare_hashes(old_hash, new_hash)
25
- old_keys = old_hash.keys
26
- new_keys = new_hash.keys
27
- keys = (old_keys + new_keys).uniq
28
-
29
- result = {
30
- append: {},
31
- remove: {},
32
- update: {}
33
- }
25
+ keys = (old_hash.keys + new_hash.keys).uniq
26
+ result = get_diffs_struct
34
27
  keys.each do |k|
35
28
  if !old_hash.has_key? k
36
29
  result[:append][k] = new_hash[k]
37
30
  elsif !new_hash.has_key? k
38
31
  result[:remove][k] = new_hash[k]
39
32
  else
40
- res = compare_elements(old_hash[k], new_hash[k])
41
- result[:update][k] = res unless res.empty?
33
+ diff = compare_elements(old_hash[k], new_hash[k])
34
+ result[:update][k] = diff unless diff.empty?
42
35
  end
43
36
  end
44
37
  filter_results(result)
@@ -49,11 +42,7 @@ module JsonCompare
49
42
  new_array_length = new_array.count
50
43
  inters = [old_array.count, new_array.count].min
51
44
 
52
- result = {
53
- append: {},
54
- remove: {},
55
- update: {}
56
- }
45
+ result = get_diffs_struct
57
46
 
58
47
  (0..inters).map do |n|
59
48
  res = compare_elements(old_array[n], new_array[n])
@@ -75,11 +64,7 @@ module JsonCompare
75
64
  end
76
65
 
77
66
  def compare_hash_array(old_hash, new_array)
78
- result = {
79
- append: {},
80
- remove: {},
81
- update: {}
82
- }
67
+ result = get_diffs_struct
83
68
 
84
69
  (0..new_array.count).map do |n|
85
70
  next if new_array[n].nil?
@@ -98,6 +83,11 @@ module JsonCompare
98
83
  (old_string != new_string) ? new_string.to_s : ""
99
84
  end
100
85
 
86
+ # Returns diffs-hash with bare structure
87
+ def get_diffs_struct
88
+ {:append => {}, :remove => {},:update => {}}
89
+ end
90
+
101
91
  def filter_results(result)
102
92
  return {} if result.nil?
103
93
  out_result = {}
@@ -1,3 +1,3 @@
1
1
  module JsonCompare
2
- VERSION = "0.1"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json-compare
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-07 00:00:00.000000000 Z
12
+ date: 2012-08-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -68,10 +68,12 @@ extra_rdoc_files: []
68
68
  files:
69
69
  - .gitignore
70
70
  - .rspec
71
+ - .travis.yml
71
72
  - Gemfile
72
73
  - LICENSE
73
74
  - README.md
74
75
  - Rakefile
76
+ - TODO
75
77
  - json-compare.gemspec
76
78
  - lib/json-compare.rb
77
79
  - lib/json-compare/comparer.rb