leenookx-json-mangler 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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.2
1
+ 0.2.3
data/json-mangler.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{json-mangler}
8
- s.version = "0.2.2"
8
+ s.version = "0.2.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["lee nookx"]
@@ -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
- @output << key << ": " << res.to_s
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
- @output << key << ": " << res.to_s
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
- @output << @input.getch
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: leenookx-json-mangler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - lee nookx