lib/json/streamer/json_streamer.rb in json-streamer-0.6.0 vs lib/json/streamer/json_streamer.rb in json-streamer-1.0.0

- old
+ new

@@ -18,21 +18,24 @@ @temp_aggregator_keys = {} @parser.start_object {start_object} @parser.start_array {start_array} @parser.key {|k| key(k)} - end # Callbacks containing `yield` have to be defined in the method called via block otherwise yield won't work def get(nesting_level:-1, key:nil, yield_values:true) yield_nesting_level = nesting_level wanted_key = key @parser.value do |v| if @aggregator[@current_nesting_level].kind_of? Array - @aggregator[@current_nesting_level] << v + if yield_values and yield_value?(yield_nesting_level) + yield v + else + @aggregator[@current_nesting_level] << v + end else @aggregator[@current_nesting_level][@current_key] = v if yield_values and yield_value?(yield_nesting_level, wanted_key) yield v end @@ -68,11 +71,11 @@ def yield_object?(yield_nesting_level, wanted_key) @current_nesting_level.eql? yield_nesting_level or (not wanted_key.nil? and wanted_key == @temp_aggregator_keys[@current_nesting_level-1]) end - def yield_value?(yield_nesting_level, wanted_key) - (@current_nesting_level + 1).eql? yield_nesting_level or wanted_key == @current_key + def yield_value?(yield_nesting_level, wanted_key = nil) + (@current_nesting_level + 1).eql? yield_nesting_level or (not wanted_key.nil? and wanted_key == @current_key) end def start_object @temp_aggregator_keys[@current_nesting_level] = @current_key @current_nesting_level += 1