Class | JSON::Pure::Generator::State
In: | lib/json/pure/generator.rb
Parent: | Object

This class is used to create State instances, that are use to hold data while generating a JSON text from a Ruby data structure.

### Methods

[] allow_nan? ascii_only? check_circular? configure from_state generate merge new quirks_mode? to_h

### Attributes

array_nl | [RW] | This string is put at the end of a line that holds a JSON array.
depth | [RW] | This integer returns the current depth data structure nesting in the generated JSON.
indent | [RW] | This string 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.
object_nl | [RW] | This string is put at the end of a line that holds a JSON object (or Hash).
quirks_mode | [RW] | If this attribute is set to true, quirks mode is enabled, otherwise it‘s disabled.
space | [RW] | This string is used to insert a space between the tokens in a JSON string.
space_before | [RW] | This string is used to insert a space before the ’:’ in JSON objects.

### Public Class methods

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.

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: ’’),
- check_circular: is deprecated now, use the :max_nesting option instead,
- max_nesting: sets the maximum level of data structure nesting in the generated JSON, max_nesting = 0 if no maximum should be checked.
- 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.
- quirks_mode: Enables quirks_mode for parser, that is for example generating single JSON values instead of documents is possible.

### Public Instance methods

[](name)

Return the value returned by method `name`.

allow_nan?()

Returns true if NaN, Infinity, and -Infinity should be considered as valid JSON and output.

ascii_only?()

Returns true, if only ASCII characters should be generated. Otherwise returns false.

check_circular?()

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

configure(opts)

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

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 GeneratorError exception.

merge(opts)

Alias for configure

quirks_mode?()

Returns true, if quirks mode is enabled. Otherwise returns false.

to_h()

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

[Validate]