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 newState
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
-
#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.
-
#buffer_initial_length
rw
This integer returns the current inital length of the buffer.
-
#buffer_initial_length=(length)
rw
This sets the initial length of the buffer to
length
, iflength
> 0, otherwise its value isn't changed. -
#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
This string is used to indent levels in the ::JSON text.
-
#indent=(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.
-
#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).
-
#quirks_mode ⇒ Boolean
(also: #quirks_mode?)
rw
Returns true, if quirks mode is enabled.
-
#quirks_mode=(enable)
rw
If set to true, enables the quirks_mode mode.
-
#quirks_mode? ⇒ Boolean
rw
Alias for #quirks_mode.
-
#space
rw
This string is used to insert a space between the tokens in a ::JSON string.
-
#space=(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.
-
#space_before=(space_before)
rw
This string is used to insert a space before the ':' in ::JSON objects.
- #allow_nan? ⇒ Boolean readonly
- #ascii_only? ⇒ Boolean readonly
-
#check_circular? ⇒ Boolean
readonly
Returns true, if circular data structures should be checked, otherwise returns false.
Instance Method Summary
-
#[](name)
Return the value returned by method
name
. -
#[]=(name, value)
Set the attribute name to value.
-
#configure(opts)
Alias for #merge.
-
#generate(obj)
Generates a valid ::JSON document from object
obj
and returns the result. -
#initialize_copy(orig)
Initializes this object from orig if it to be duplicated/cloned and returns it.
-
#merge(opts)
(also: #configure)
Configure this
State
instance with the Hash opts, and return itself. -
#to_h ⇒ Hash
(also: #to_hash)
Returns the configuration instance variables as a hash, that can be passed to the configure method.
-
#to_hash ⇒ Hash
Alias for #to_h.
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.
-
quirks_mode: Enables quirks_mode for parser, that is for example generating single JSON values instead of documents is possible.
-
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)
#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)
#buffer_initial_length (rw)
This integer returns the current inital 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)
This string is used to indent levels in the ::JSON text.
#indent=(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.
#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).
#quirks_mode ⇒ Boolean
(rw) Also known as: #quirks_mode?
Returns true, if quirks mode is enabled. Otherwise returns false.
#quirks_mode=(enable) (rw)
If set to true, enables the quirks_mode mode.
#quirks_mode ⇒ Boolean
(rw)
#quirks_mode? ⇒ Boolean
Boolean
(rw)
#quirks_mode? ⇒ Boolean
Alias for #quirks_mode.
#space (rw)
This string is used to insert a space between the tokens in a ::JSON string.
#space=(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.
#space_before=(space_before) (rw)
This string is used to insert a space before the ':' in ::JSON objects.
Instance Method Details
#[](name)
Return the value returned by method name
.
#[]=(name, value)
Set 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 to be duplicated/cloned and returns it.
#merge(opts) Also known as: #configure
Configure this State
instance with the Hash opts, and return itself.
#to_h ⇒ Hash
Also known as: #to_hash
Returns the configuration instance variables as a hash, that can be passed to the configure method.
#to_h ⇒ Hash
#to_hash ⇒ Hash
Hash
#to_hash ⇒ Hash
Alias for #to_h.