Class: ToonFormat::Encoder
- Inherits:
-
Object
- Object
- ToonFormat::Encoder
- Defined in:
- lib/toon_format/encoder.rb
Overview
Encodes Ruby objects to TOON format strings
Constant Summary collapse
- DEFAULT_OPTIONS =
{ delimiter: ",", indent: 2, length_marker: true }.freeze
- MAX_DEPTH =
100- MAX_ARRAY_SIZE =
100_000
Class Method Summary collapse
-
.encode(data, options = {}) ⇒ String
Encode Ruby object to TOON format string.
Instance Method Summary collapse
-
#encode(data, depth = 0) ⇒ Object
Main encode method.
-
#initialize(options = {}) ⇒ Encoder
constructor
A new instance of Encoder.
Constructor Details
#initialize(options = {}) ⇒ Encoder
Returns a new instance of Encoder.
24 25 26 27 28 |
# File 'lib/toon_format/encoder.rb', line 24 def initialize( = {}) @options = DEFAULT_OPTIONS.merge() @indent_level = 0 @visited = Set.new end |
Class Method Details
.encode(data, options = {}) ⇒ String
Encode Ruby object to TOON format string
20 21 22 |
# File 'lib/toon_format/encoder.rb', line 20 def self.encode(data, = {}) new().encode(data) end |
Instance Method Details
#encode(data, depth = 0) ⇒ Object
Main encode method
31 32 33 34 |
# File 'lib/toon_format/encoder.rb', line 31 def encode(data, depth = 0) check_depth(depth) encode_value(data, depth) end |