123456789_123456789_123456789_123456789_123456789_

Class: JSON::Ext::Generator::State

Relationships & Source Files
Inherits: Object
Defined in: ext/json/generator/generator.c

Class Method Summary

  • .from_state(opts)

    Creates a State object from opts, which ought to be Hash to create a new State instance configured by opts, something else to create an unconfigured instance.

  • .new(opts = {}) constructor

    Instantiates a new State object, configured by opts.

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(opts = {})

Instantiates a new State object, configured by opts.

opts can have the following keys:

  • indent: a string used to indent levels (default: ''),

  • space: a string that is put after, a : or , delimiter (default: ''),

  • space_before: a string that is put before a : pair delimiter (default: ''),

  • object_nl: a string that is put at the end of a ::JSON object (default: ''),

  • array_nl: a string that is put at the end of a ::JSON array (default: ''),

  • allow_nan: true if NaN, Infinity, and -Infinity should be generated, otherwise an exception is thrown, if these values are encountered. This options defaults to false.

  • buffer_initial_length: sets the initial length of the generator's internal buffer.

Class Method Details

.from_state(opts)

Creates a State object from opts, which ought to be Hash to create a new State instance configured by opts, something else to create an unconfigured instance. If opts is a State object, it is just returned.

Instance Attribute Details

#allow_nan?Boolean (readonly)

Returns true, if NaN, Infinity, and -Infinity should be generated, otherwise returns false.

#array_nl (rw)

This string is put at the end of a line that holds a ::JSON array.

#array_nl=(array_nl) (rw)

This string is put at the end of a line that holds a ::JSON array.

#ascii_only?Boolean (readonly)

Returns true, if NaN, Infinity, and -Infinity should be generated, otherwise returns false.

#buffer_initial_length (rw)

This integer returns the current initial length of the buffer.

#buffer_initial_length=(length) (rw)

This sets the initial length of the buffer to length, if length > 0, otherwise its value isn't changed.

#check_circular?Boolean (readonly)

Returns true, if circular data structures should be checked, otherwise returns false.

#depth (rw)

This integer returns the current depth of data structure nesting.

#depth=(depth) (rw)

This sets the maximum level of data structure nesting in the generated ::JSON to the integer depth, max_nesting = 0 if no maximum should be checked.

#indent (rw)

Returns the string that is used to indent levels in the ::JSON text.

#indent=(indent) (rw)

Sets the string that is used to indent levels in the ::JSON text.

#max_nesting (rw)

This integer returns the maximum level of data structure nesting in the generated ::JSON, max_nesting = 0 if no maximum is checked.

#max_nesting=(depth) (rw)

This sets the maximum level of data structure nesting in the generated ::JSON to the integer depth, max_nesting = 0 if no maximum should be checked.

#object_nl (rw)

This string is put at the end of a line that holds a ::JSON object (or Hash).

#object_nl=(object_nl) (rw)

This string is put at the end of a line that holds a ::JSON object (or Hash).

#space (rw)

Returns the string that is used to insert a space between the tokens in a ::JSON string.

#space=(space) (rw)

Sets space to the string that is used to insert a space between the tokens in a ::JSON string.

#space_before (rw)

Returns the string that is used to insert a space before the ':' in ::JSON objects.

#space_before=(space_before) (rw)

Sets the string that is used to insert a space before the ':' in ::JSON objects.

Instance Method Details

#[](name)

Returns the value returned by method name.

#[]=(name, value)

Sets the attribute name to value.

#merge(opts) #configure(opts)

Alias for #merge.

#generate(obj)

Generates a valid ::JSON document from object obj and returns the result. If no valid ::JSON document can be created this method raises a ::JSON::GeneratorError exception.

#initialize_copy(orig)

Initializes this object from orig if it can be duplicated/cloned and returns it.

#merge(opts) Also known as: #configure

Configure this State instance with the Hash opts, and return itself.

#to_hHash Also known as: #to_hash

Returns the configuration instance variables as a hash, that can be passed to the configure method.

#to_hHash #to_hashHash

Alias for #to_h.