Module: JsonToToon

Defined in:
lib/json_to_toon.rb,
lib/json_to_toon/encoder.rb,
lib/json_to_toon/version.rb

Defined Under Namespace

Classes: CircularReferenceError, Encoder, Error, InvalidOptionError

Constant Summary collapse

VERSION =
'0.2.0'

Class Method Summary collapse

Class Method Details

.convert(value, options = {}) ⇒ Object

Alias for encode



34
35
36
# File 'lib/json_to_toon.rb', line 34

def self.convert(value, options = {})
  encode(value, options)
end

.encode(value, options = {}) ⇒ String

Convert a Ruby object to TOON format

Examples:

Basic usage

JsonToToon.encode({name: 'Ada', age: 30})
# => "name: Ada\nage: 30"

With tab delimiter

JsonToToon.encode({tags: ['a', 'b']}, delimiter: "\t")
# => "tags[2\t]: a\tb"

Parameters:

  • value (Object)

    The Ruby object to encode (Hash, Array, or primitive)

  • options (Hash) (defaults to: {})

    Encoding options

Options Hash (options):

  • :indent (Integer)

    Number of spaces per indentation level (default: 2)

  • :delimiter (String)

    Delimiter for arrays: ‘,’ (default), “t”, or ‘|’

  • :length_marker (String, false)

    Length marker character or false (default: false)

Returns:

  • (String)

    TOON-formatted string with no trailing newline

Raises:



29
30
31
# File 'lib/json_to_toon.rb', line 29

def self.encode(value, options = {})
  Encoder.new(options).encode(value)
end