leenookx-json-mangler 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/json-mangler.gemspec +1 -1
- data/lib/json-mangler/json_extractor.rb +18 -7
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.3
|
data/json-mangler.gemspec
CHANGED
@@ -15,6 +15,7 @@ class JSONExtractor
|
|
15
15
|
@force_capture = false
|
16
16
|
@capture_depth = depth - 1
|
17
17
|
@current_depth = 0
|
18
|
+
@num_fragments = 0
|
18
19
|
|
19
20
|
@input = StringScanner.new( input )
|
20
21
|
@searchval = '"' + search + '"'
|
@@ -94,7 +95,8 @@ class JSONExtractor
|
|
94
95
|
end
|
95
96
|
|
96
97
|
if !@force_capture and capture
|
97
|
-
|
98
|
+
fragment = key + ": " + res.to_s
|
99
|
+
add_json_fragment( fragment )
|
98
100
|
|
99
101
|
# We've stopped capturing locally...
|
100
102
|
capture = false
|
@@ -103,7 +105,8 @@ class JSONExtractor
|
|
103
105
|
# Handle special case of array match
|
104
106
|
if @force_capture
|
105
107
|
if @current_depth == -1
|
106
|
-
|
108
|
+
fragment = key + ": " + res.to_s
|
109
|
+
add_json_fragment( fragment )
|
107
110
|
@force_capture = false
|
108
111
|
@current_depth = 0
|
109
112
|
end
|
@@ -120,16 +123,16 @@ class JSONExtractor
|
|
120
123
|
# object?
|
121
124
|
if @force_capture and @current_depth == 0
|
122
125
|
last_pos = @input.pos
|
123
|
-
|
124
|
-
puts "Full object capture: " + start_pos.to_s + " -> " + last_pos.to_s
|
125
|
-
|
126
126
|
cur_pos = start_pos
|
127
127
|
@input.pos = cur_pos
|
128
|
+
fragment = ""
|
128
129
|
while (cur_pos < last_pos)
|
129
|
-
|
130
|
+
fragment << @input.getch
|
130
131
|
cur_pos = cur_pos + 1
|
131
132
|
end
|
132
133
|
|
134
|
+
add_json_fragment( fragment )
|
135
|
+
|
133
136
|
@force_capture = false
|
134
137
|
else
|
135
138
|
# No, we need to 'descend' further
|
@@ -178,7 +181,6 @@ class JSONExtractor
|
|
178
181
|
# If we're in data matching mode and this matches the
|
179
182
|
# value that we are searching for...
|
180
183
|
if @mode == 2 and string == @searchval and @capture_depth > 0
|
181
|
-
puts "marked"
|
182
184
|
@force_capture = true
|
183
185
|
@current_depth = @capture_depth
|
184
186
|
end
|
@@ -217,5 +219,14 @@ class JSONExtractor
|
|
217
219
|
def trim_space
|
218
220
|
@input.scan(/\s+/)
|
219
221
|
end
|
222
|
+
|
223
|
+
def add_json_fragment( fragment )
|
224
|
+
@num_fragments = @num_fragments + 1
|
225
|
+
if @num_fragments > 1
|
226
|
+
@output << ", "
|
227
|
+
end
|
228
|
+
|
229
|
+
@output << fragment
|
230
|
+
end
|
220
231
|
end
|
221
232
|
|