Last active
November 6, 2017 06:04
-
-
Save vonKingsley/ddbca4ddb9d55669c4ea4bbc9a6e4d9d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "json" | |
class Base | |
def create_json | |
io = IO::Memory.new | |
b = JSON::Builder.new(io) | |
b.start_document | |
b.start_object | |
self.to_json(b) | |
b.end_object | |
b.end_document | |
io.to_s | |
end | |
def to_json(builder) | |
builder.scalar nil | |
end | |
end | |
class Ext < Base | |
def to_json(builder) | |
builder.field "audio" do | |
builder.object do | |
builder.field "num_channels", "1" | |
end | |
end | |
builder.field "base" do | |
super(builder) | |
end | |
# avoid nil values by converting nil=0 | |
builder.field "direction", "Incoming" | |
builder.field "encryption", "no" | |
builder.field "bytes", 1324 | |
builder.field "channel_rate", 3 | |
builder.field "drop", 4 | |
builder.field "jitter", 3 | |
builder.field "last_interval_lost", 2 | |
builder.field "last_interval_received", 1 | |
builder.field "loss", 5 | |
builder.field "max_jitter", 5 | |
end | |
end | |
x = Ext.new.create_json | |
p x.to_s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment