Module: ContextSpook::TOON

Included in:
Generator::Context
Defined in:
lib/context_spook/toon.rb,
lib/context_spook/toon/encoder.rb

Overview

The ContextSpook::TOON module provides TOON (Token-Oriented Object Notation) v4 serialization functionality for context objects.

Defined Under Namespace

Classes: Encoder

Instance Method Summary collapse

Instance Method Details

#to_toon ⇒ String

Converts the context object to TOON v4 format.

Uses a fast JSON round-trip (C-optimized) to normalize the data, then walks the canonical Hash/Array tree with our native encoder.

Returns:

  • (String) —

    the TOON-encoded representation of the context



13
14
15
# File 'lib/context_spook/toon.rb', line 13

def to_toon
  Encoder.encode(as_json)
end

#to_toon_stream(output) ⇒ Object

Streams the TOON v4 output to the given IO.

Parameters:

  • output (IO) —

    the IO to write to (e.g. STDOUT, File, StringIO)



28
29
30
# File 'lib/context_spook/toon.rb', line 28

def to_toon_stream(output)
  Encoder.encode(as_json, output: output)
end

#toon_size ⇒ Integer

Calculates the size of the TOON representation.

Returns:

  • (Integer) —

    the size in bytes of the TOON representation



21
22
23
# File 'lib/context_spook/toon.rb', line 21

def toon_size
  to_toon.bytesize
end