scon 0.0.4 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/scon/constants.rb +2 -1
- data/lib/scon/generator.rb +30 -14
- data/lib/scon/parser.rb +5 -0
- data/lib/scon/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: 1c2d9ac985fa59d6375f9315587cb79a1a21f65e
|
4
|
+
data.tar.gz: ab452a608097d43291f47abaa819c83f7c27693d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d4f49d939c0d02488a28975a19f0d89211ef3fcd8136875ec26ff7954273fc079d9381f6a55bfb08459983cd28289b5499a4e7387a3c2f05d04343e30e73210
|
7
|
+
data.tar.gz: 2889b3ca49a2358eb7360d6f0ab92aa434f4cd04b81cb2e4a9aaa8d91acace3fd43497e8ce082fbb3a10a01c26af314f64852f55ca0e2ac2a3d8bcaeb62f68d2
|
data/lib/scon/constants.rb
CHANGED
data/lib/scon/generator.rb
CHANGED
@@ -75,19 +75,39 @@ private
|
|
75
75
|
encode_value k, v, :hash
|
76
76
|
end
|
77
77
|
elsif object.is_a? Array
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
78
|
+
encode_array object
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def encode_array object
|
83
|
+
is_nil = false
|
84
|
+
nilcount = 0
|
85
|
+
object.each_with_index do |v, i|
|
86
|
+
if v.nil?
|
87
|
+
is_nil = true
|
88
|
+
nilcount += 1
|
89
|
+
else
|
90
|
+
if is_nil
|
91
|
+
if nilcount > 2
|
92
|
+
@body_bytes << Constants::DATA[:arr_padding]
|
93
|
+
@body_bytes << auto_number(nilcount)
|
94
|
+
else
|
95
|
+
nilcount.times { @body_bytes << Constants::DATA[:nil] }
|
96
|
+
end
|
97
|
+
end
|
98
|
+
is_nil = false
|
99
|
+
nilcount = 0
|
100
|
+
|
101
|
+
encode_value i, v, :array
|
82
102
|
end
|
83
103
|
end
|
84
104
|
end
|
85
105
|
|
86
|
-
def encode_value key, value, parent_type
|
106
|
+
def encode_value key, value, parent_type
|
87
107
|
instruct, serial = 0, nil
|
88
108
|
if value.is_a? Hash
|
89
109
|
@body_bytes << Constants::DATA[:obj_start]
|
90
|
-
encode_key key, parent_type
|
110
|
+
encode_key key, parent_type
|
91
111
|
value.each do |k, v|
|
92
112
|
encode_value k, v, :hash
|
93
113
|
end
|
@@ -95,12 +115,8 @@ private
|
|
95
115
|
return
|
96
116
|
elsif value.is_a? Array
|
97
117
|
@body_bytes << Constants::DATA[:arr_start]
|
98
|
-
encode_key key, parent_type
|
99
|
-
|
100
|
-
value.each_with_index do |v, i|
|
101
|
-
encode_value i, v, :array, counter
|
102
|
-
counter += 1
|
103
|
-
end
|
118
|
+
encode_key key, parent_type
|
119
|
+
encode_array value
|
104
120
|
@body_bytes << Constants::DATA[:arr_end]
|
105
121
|
return
|
106
122
|
elsif value.is_a?(Fixnum) || value.is_a?(Bignum)
|
@@ -121,11 +137,11 @@ private
|
|
121
137
|
end
|
122
138
|
|
123
139
|
@body_bytes << instruct
|
124
|
-
encode_key key, parent_type
|
140
|
+
encode_key key, parent_type
|
125
141
|
@body_bytes << serial unless serial.nil?
|
126
142
|
end
|
127
143
|
|
128
|
-
def encode_key key, parent_type
|
144
|
+
def encode_key key, parent_type
|
129
145
|
if parent_type == :hash
|
130
146
|
keys = key.to_s
|
131
147
|
encode_key_hash keys
|
data/lib/scon/parser.rb
CHANGED
@@ -122,6 +122,11 @@ private
|
|
122
122
|
closed = true
|
123
123
|
next
|
124
124
|
end
|
125
|
+
if data_type == Constants::DATA[:arr_padding]
|
126
|
+
count = parse_value @data.shift
|
127
|
+
count.times { parent << nil }
|
128
|
+
data_type = @data.shift
|
129
|
+
end
|
125
130
|
data_value = parse_value data_type
|
126
131
|
parent << data_value
|
127
132
|
|
data/lib/scon/version.rb
CHANGED