json_normalizer 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/json_normalizer.rb +47 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a7c72e2a21f7d48050e64579ad670f273a734a80
|
4
|
+
data.tar.gz: 6aef7211f0a3450e41a73d6df1767308ea6a4b81
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cc393bd7560f61124738a0dab437b54041cf087f6f731083fde88d1ccb4fb296c93ee8ec5952685be7691988ef7eafcde8099c9c31561fd02bd0853d0f2c5686
|
7
|
+
data.tar.gz: 5c1e5851fee831d82ab0c888294989616884f3a2ed03a0fd73e8cebb9739222b5d4debcfc09c78c617c942c8488b72d3814cd969478c9ce2f63cbad0a5e7d59b
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'byebug'
|
3
|
+
|
4
|
+
class Json_Normalizer
|
5
|
+
|
6
|
+
# Init requires pre defined JSON map.
|
7
|
+
# Ex. { "this_key": ["morphed", "to", "this_key"] }
|
8
|
+
def initialize(map)
|
9
|
+
@map = JSON.parse(map)
|
10
|
+
@result = {}
|
11
|
+
end
|
12
|
+
|
13
|
+
def key_contained?(key)
|
14
|
+
@map.keys.each{ |k| return true if @map[k].include?(key.to_s) }
|
15
|
+
return false
|
16
|
+
end
|
17
|
+
|
18
|
+
def fetch_key(key)
|
19
|
+
@map.keys.each{ |k| return k if @map[k].include?(key) }
|
20
|
+
end
|
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
|
+
|
31
|
+
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)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# json.map{ |k, v| [k.to_s, v] }.to_h
|
44
|
+
JSON.parse json.to_json
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: json_normalizer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Evan Tetzlaff
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-05-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: guard
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: guard-rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: byebug
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Normalizes disparate JSON Schemas to Specified Schema
|
70
|
+
email: reuhssurance@gmail.com
|
71
|
+
executables: []
|
72
|
+
extensions: []
|
73
|
+
extra_rdoc_files: []
|
74
|
+
files:
|
75
|
+
- lib/json_normalizer.rb
|
76
|
+
homepage: http://rubygems.org/gems/json_normalizer
|
77
|
+
licenses:
|
78
|
+
- MIT
|
79
|
+
metadata: {}
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 2.5.1
|
97
|
+
signing_key:
|
98
|
+
specification_version: 4
|
99
|
+
summary: Normalizes JSON Doc Schema.
|
100
|
+
test_files: []
|