asciinema.org/app/streamers/json_streamer.rb

29 lines
430 B
Ruby
Raw Normal View History

2013-08-13 17:49:48 +00:00
class JsonStreamer
def initialize(object)
@object = object
end
def each(&blk)
yield '{'
@object.each_with_index do |key_value, i|
key, value = key_value
yield %("#{key}":)
if value.respond_to?(:call)
value.call do |v|
yield v.to_s
end
else
yield value.to_json
end
yield ',' unless i + 1 == @object.size
end
yield '}'
end
end