class TurboStreamer::WankelEncoder
Public Class Methods
new(io, options={})
click to toggle source
Calls superclass method
# File lib/turbostreamer/encoders/wankel.rb, line 6 def initialize(io, options={}) @stack = [] @indexes = [] super(io, {mode: :as_json}.merge(options)) end
Public Instance Methods
array_close()
click to toggle source
Calls superclass method
# File lib/turbostreamer/encoders/wankel.rb, line 42 def array_close @indexes.pop @stack.pop super end
array_open()
click to toggle source
Calls superclass method
# File lib/turbostreamer/encoders/wankel.rb, line 36 def array_open @stack << :array @indexes << 0 super end
capture(to=nil) { || ... }
click to toggle source
# File lib/turbostreamer/encoders/wankel.rb, line 66 def capture(to=nil) flush old_output = self.output to = to || ::StringIO.new @indexes << 0 self.output = to yield flush to.string.sub(/\A,/, ''.freeze).chomp(",".freeze) ensure @indexes.pop self.output = old_output end
inject(string)
click to toggle source
# File lib/turbostreamer/encoders/wankel.rb, line 48 def inject(string) flush if @stack.last == :array self.output.write(','.freeze) if @indexes.last > 0 @indexes[-1] += 1 elsif @stack.last == :map self.output.write(','.freeze) if @indexes.last > 0 capture do string("".freeze) string("".freeze) end @indexes[-1] += 1 end self.output.write(string) end
key(k)
click to toggle source
# File lib/turbostreamer/encoders/wankel.rb, line 13 def key(k) string(k) end
map_close()
click to toggle source
Calls superclass method
# File lib/turbostreamer/encoders/wankel.rb, line 30 def map_close @indexes.pop @stack.pop super end
map_open()
click to toggle source
Calls superclass method
# File lib/turbostreamer/encoders/wankel.rb, line 24 def map_open @stack << :map @indexes << 0 super end
value(v)
click to toggle source
Calls superclass method
# File lib/turbostreamer/encoders/wankel.rb, line 17 def value(v) if @stack.last == :array || @stack.last == :map @indexes[-1] += 1 end super end