json_normalizer 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/json_normalizer.rb +35 -12
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a7c72e2a21f7d48050e64579ad670f273a734a80
4
- data.tar.gz: 6aef7211f0a3450e41a73d6df1767308ea6a4b81
3
+ metadata.gz: 4b1855581218bf47b302951a5547c085e4cbf05a
4
+ data.tar.gz: 13657ff88bf9a9af352f20fc4620d818de0d9c0c
5
5
  SHA512:
6
- metadata.gz: cc393bd7560f61124738a0dab437b54041cf087f6f731083fde88d1ccb4fb296c93ee8ec5952685be7691988ef7eafcde8099c9c31561fd02bd0853d0f2c5686
7
- data.tar.gz: 5c1e5851fee831d82ab0c888294989616884f3a2ed03a0fd73e8cebb9739222b5d4debcfc09c78c617c942c8488b72d3814cd969478c9ce2f63cbad0a5e7d59b
6
+ metadata.gz: 6b618106c9863dbf04235bf202ac6b74e39af1fc095922794f37fe761f4239ae62b0abc61dfbb7b00065c670dc355c7a43c357488576f004cfa97ba88237f066
7
+ data.tar.gz: b30c1daa700c300e1b003a378734a906298e1f5ef6394b6720b76bc54c4e0593d873a5e322072d9f3346e563f294d1c9cb2c74c961c4228db4d55ec16cb6294b
@@ -19,29 +19,52 @@ class Json_Normalizer
19
19
  @map.keys.each{ |k| return k if @map[k].include?(key) }
20
20
  end
21
21
 
22
+ # def swap_key(json, key)
23
+ # if self.key_contained?(key)
24
+ # json[self.fetch_key(key).first] = json[key]
25
+ # json.delete(key)
26
+ # else
27
+ # # if we want to move out non-normalized keys into a different 'misc' key or something
28
+ # end
29
+ # end
30
+
22
31
  def swap_key(json, key)
23
32
  if self.key_contained?(key)
24
- json[self.fetch_key(key).first] = json[key]
33
+ json[self.fetch_key(key)] = json[key]
25
34
  json.delete(key)
26
- else
27
- # if we want to move out non-normalized keys into a different 'misc' key or something
28
35
  end
29
36
  end
30
37
 
31
38
  def translate(json)
32
- json = JSON.parse(json) if !json.is_a?(Hash)
33
- json.keys.each do |key|
34
- if json[key].respond_to?(:each)
35
- puts "Key: #{key} recursing..."
36
- self.translate(json[key])
37
- self.swap_key(json, key)
38
- else
39
- self.swap_key(json, key)
39
+ # json = JSON.parse(json) if !json.is_a?(Hash)
40
+ json = JSON.parse(json) if ![Hash, Array].include?(json.class)
41
+ if json.is_a?(Array)
42
+ json.each do |j|
43
+ j.keys.each do |key|
44
+ if j[key].respond_to?(:each)
45
+ puts "Key: #{key} recursing..."
46
+ self.translate(j[key])
47
+ self.swap_key(j, key)
48
+ else
49
+ self.swap_key(j, key)
50
+ end
51
+ end
52
+ end
53
+ else
54
+ json.keys.each do |key|
55
+ if json[key].respond_to?(:each)
56
+ puts "Key: #{key} recursing..."
57
+ self.translate(json[key])
58
+ self.swap_key(json, key)
59
+ else
60
+ self.swap_key(json, key)
61
+ end
40
62
  end
41
63
  end
42
64
 
43
65
  # json.map{ |k, v| [k.to_s, v] }.to_h
44
- JSON.parse json.to_json
66
+ # JSON.parse json.to_json
67
+ json
45
68
  end
46
69
 
47
70
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_normalizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evan Tetzlaff