jsonx 0.2.2 → 0.2.3
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
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/jsonx.rb +18 -14
- metadata +4 -4
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8164d5e06dffd753cb2022ec4c03b66c612755e4
|
|
4
|
+
data.tar.gz: d8828773b49e32d62e54aa21399fe821c9c3c324
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2f4a06a5ffbf83a415aa2a558c2fc8acbfc7c460668829846cb0a4f2f1f67cf6abbd3ec7fee728018a830b20323482dc65abfe7039501b7de43fd5ff668632a6
|
|
7
|
+
data.tar.gz: d9e9fc53560648903e04a32a0f881768caf0919f5f1ccf7eb8771286202c6cd746400e857c1842e0654cf50b4e656c76a2284b0206531865ccae1a7957344242
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
data.tar.gz.sig
CHANGED
|
Binary file
|
data/lib/jsonx.rb
CHANGED
|
@@ -26,12 +26,16 @@ class JSONx
|
|
|
26
26
|
|
|
27
27
|
|
|
28
28
|
end
|
|
29
|
+
|
|
30
|
+
alias to_jsonx to_s
|
|
31
|
+
alias to_xml to_s
|
|
29
32
|
|
|
30
33
|
private
|
|
31
34
|
|
|
32
35
|
def json_to_jsonx(h)
|
|
36
|
+
|
|
33
37
|
types = {
|
|
34
|
-
|
|
38
|
+
Hash: ->(k, h){
|
|
35
39
|
type = 'json:object'
|
|
36
40
|
[type, '', (k.empty? ? {} : {name: k}),
|
|
37
41
|
*h.map {|k2,v| types[v.class.to_s.to_sym].call(k2, v)}
|
|
@@ -39,14 +43,15 @@ class JSONx
|
|
|
39
43
|
},
|
|
40
44
|
FalseClass: ->(k, b){ ['json:boolean',
|
|
41
45
|
b.to_s, k.empty? ? {} : {name: k}]},
|
|
42
|
-
|
|
46
|
+
TrueClass: ->(k, b){ ['json:boolean',
|
|
43
47
|
b.to_s, k.empty? ? {} : {name: k}]},
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
+
Fixnum: ->(k, n){ ['json:number', n, k.empty? ? {} : {name: k}]},
|
|
49
|
+
Float: ->(k, n){ ['json:number', n, k.empty? ? {} : {name: k}]},
|
|
50
|
+
NilClass: ->(k, n){ ['json:null', '', k.empty? ? {} : {name: k}]},
|
|
51
|
+
String: ->(k, s){ ['json:string', s, k.empty? ? {} : {name: k}]},
|
|
52
|
+
Array: ->(k, a){
|
|
48
53
|
['json:array', '', {name: k},
|
|
49
|
-
*a.map{|y| types[y.class.to_s.to_sym].call('', y
|
|
54
|
+
*a.map{|y| types[y.class.to_s.to_sym].call('', y)}
|
|
50
55
|
]
|
|
51
56
|
}
|
|
52
57
|
}
|
|
@@ -64,16 +69,15 @@ class JSONx
|
|
|
64
69
|
|
|
65
70
|
types = {
|
|
66
71
|
boolean: ->(e){ e.text.downcase == 'true' },
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
72
|
+
string: ->(e){ e.text },
|
|
73
|
+
null: ->(e){ nil },
|
|
74
|
+
number: ->(e){ s = e.text; s.to_i == s.to_f ? s.to_i : s.to_f},
|
|
75
|
+
array: ->(e){
|
|
71
76
|
e.elements.map {|x| types[x.name[/\w+$/].to_sym].call x }
|
|
72
77
|
},
|
|
73
|
-
|
|
78
|
+
object: ->(e){
|
|
74
79
|
e.elements.inject({}) do |r, x|
|
|
75
|
-
name
|
|
76
|
-
r.merge(x.attributes[:name] => types[name.to_sym].call(x))
|
|
80
|
+
r.merge(x.attributes[:name] => types[x.name[/\w+$/].to_sym].call(x))
|
|
77
81
|
end
|
|
78
82
|
}
|
|
79
83
|
}
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: jsonx
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- James Robertson
|
|
@@ -31,7 +31,7 @@ cert_chain:
|
|
|
31
31
|
oqIfSIJniA/rq0qM/Bhn+dpcKTcPQZtx+xFxMoZ25KJWupSNDOi8rtKUyPTNPrqu
|
|
32
32
|
6j3yoPh2uEBjKA==
|
|
33
33
|
-----END CERTIFICATE-----
|
|
34
|
-
date: 2014-09-
|
|
34
|
+
date: 2014-09-27 00:00:00.000000000 Z
|
|
35
35
|
dependencies:
|
|
36
36
|
- !ruby/object:Gem::Dependency
|
|
37
37
|
name: rexle
|
|
@@ -42,7 +42,7 @@ dependencies:
|
|
|
42
42
|
version: '1.0'
|
|
43
43
|
- - ">="
|
|
44
44
|
- !ruby/object:Gem::Version
|
|
45
|
-
version: 1.0.
|
|
45
|
+
version: 1.0.24
|
|
46
46
|
type: :runtime
|
|
47
47
|
prerelease: false
|
|
48
48
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -52,7 +52,7 @@ dependencies:
|
|
|
52
52
|
version: '1.0'
|
|
53
53
|
- - ">="
|
|
54
54
|
- !ruby/object:Gem::Version
|
|
55
|
-
version: 1.0.
|
|
55
|
+
version: 1.0.24
|
|
56
56
|
description:
|
|
57
57
|
email: james@r0bertson.co.uk
|
|
58
58
|
executables: []
|
metadata.gz.sig
CHANGED
|
Binary file
|