rusty_json 1.2.0 → 1.2.1
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 +4 -4
- data/lib/rusty_json/parser.rb +14 -11
- data/lib/rusty_json/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 586d28acc06307f6920e376bcae55b025ce42021
|
4
|
+
data.tar.gz: 6851dd830392776b050b8c14730267a5518e1066
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 40753f7dd3e28fec338b956250501a9bced6d0b60cced4ae1130328087725fd8ed6620e51a8b7298492a1c9b76a6cc1a587b8b67febb53e39ed675f3e1285338
|
7
|
+
data.tar.gz: a3810f86f425c2b341527a5f061bbe513ba846f28c22494f1d29b383332dcb1ee5849a03ece019f7edf7a42c76bb88fe842388c4fddb90165ea827f26730a412
|
data/lib/rusty_json/parser.rb
CHANGED
@@ -18,9 +18,8 @@ module RustyJson
|
|
18
18
|
|
19
19
|
def parse
|
20
20
|
@parsed = JSON.parse(@json)
|
21
|
-
struct = RustStruct.new(@name, true)
|
22
21
|
if @parsed.is_a? Hash
|
23
|
-
struct = parse_hash(@
|
22
|
+
struct = parse_hash(@name, @parsed)
|
24
23
|
end
|
25
24
|
struct.to_s
|
26
25
|
end
|
@@ -39,20 +38,22 @@ module RustyJson
|
|
39
38
|
end
|
40
39
|
end
|
41
40
|
|
41
|
+
def possible_new_struct(s)
|
42
|
+
match = @structs.find{|st| s == st}
|
43
|
+
s = match || s
|
44
|
+
if match.nil?
|
45
|
+
@structs << s
|
46
|
+
end
|
47
|
+
s
|
48
|
+
end
|
49
|
+
|
42
50
|
def parse_parts(name, values, struct)
|
43
51
|
if values.is_a? Array
|
44
52
|
struct = parse_array(name, values, struct)
|
45
53
|
elsif values.is_a? Hash
|
46
54
|
n = parse_name(name.split('_').collect(&:capitalize).join)
|
47
55
|
@struct_names << n
|
48
|
-
s =
|
49
|
-
s = parse_hash(values, s)
|
50
|
-
match = @structs.find{|st| s == st}
|
51
|
-
s = match || s
|
52
|
-
if match.nil?
|
53
|
-
@struct_names << n
|
54
|
-
@structs << s
|
55
|
-
end
|
56
|
+
s = possible_new_struct( parse_hash(n, values) )
|
56
57
|
struct.add_value(name, s)
|
57
58
|
else
|
58
59
|
struct = parse_value(name, values, struct)
|
@@ -60,7 +61,9 @@ module RustyJson
|
|
60
61
|
struct
|
61
62
|
end
|
62
63
|
|
63
|
-
def parse_hash(
|
64
|
+
def parse_hash(n, hash)
|
65
|
+
struct = RustStruct.new(n)
|
66
|
+
@struct_names << n
|
64
67
|
hash.each do |name, values|
|
65
68
|
struct = parse_parts(name, values, struct)
|
66
69
|
end
|
data/lib/rusty_json/version.rb
CHANGED