Class: Json::Streamer::Callbacks

Inherits:
Object
  • Object
show all
Defined in:
lib/json/streamer/callbacks.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(aggregator) ⇒ Callbacks

Returns a new instance of Callbacks.



6
7
8
# File 'lib/json/streamer/callbacks.rb', line 6

def initialize(aggregator)
  @aggregator = aggregator
end

Instance Attribute Details

#aggregatorObject (readonly)

Returns the value of attribute aggregator.



4
5
6
# File 'lib/json/streamer/callbacks.rb', line 4

def aggregator
  @aggregator
end

Instance Method Details

#end_arrayObject



31
32
33
# File 'lib/json/streamer/callbacks.rb', line 31

def end_array
  end_level { |obj| yield obj }
end

#end_objectObject



27
28
29
# File 'lib/json/streamer/callbacks.rb', line 27

def end_object
  end_level { |obj| yield obj }
end

#key(k, symbolize_keys) ⇒ Object



18
19
20
# File 'lib/json/streamer/callbacks.rb', line 18

def key(k, symbolize_keys)
  @aggregator.key = symbolize_keys ? k.to_sym : k
end

#start_arrayObject



14
15
16
# File 'lib/json/streamer/callbacks.rb', line 14

def start_array
  new_level(Array.new)
end

#start_objectObject



10
11
12
# File 'lib/json/streamer/callbacks.rb', line 10

def start_object
  new_level(Hash.new)
end

#value(value) ⇒ Object



22
23
24
25
# File 'lib/json/streamer/callbacks.rb', line 22

def value(value)
  used = yield value
  add_value(value) unless used
end