Class: BSON::Decimal128::Builder::ToString Private

Inherits:
Object
  • Object
show all
Defined in:
lib/bson/decimal128/builder.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Helper class for getting a String representation of a Decimal128 object.

Since:

  • 4.2.0

Constant Summary collapse

NAN_STRING =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

String representing a NaN value.

Returns:

  • (String)

    The string representing NaN.

Since:

  • 4.2.0

'NaN'
INFINITY_STRING =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

String representing an Infinity value.

Returns:

  • (String)

    The string representing Infinity.

Since:

  • 4.2.0

'Infinity'

Instance Method Summary collapse

Constructor Details

#initialize(decimal128) ⇒ ToString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initialize the FromBigDecimal Builder object.

Examples:

Create the ToString builder.

Builder::ToString.new(big_decimal)

Parameters:

  • decimal128 (Decimal128)

    The decimal128 object to create a String from.

Since:

  • 4.2.0



364
365
366
# File 'lib/bson/decimal128/builder.rb', line 364

def initialize(decimal128)
  @decimal128 = decimal128
end

Instance Method Details

#stringString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Note:

The returned string may be frozen.

Get the string representing the Decimal128 object.

Examples:

Get a string representing the decimal128.

builder.string

Returns:

  • (String)

    The string representing the decimal128 object.

Since:

  • 4.2.0



378
379
380
381
382
# File 'lib/bson/decimal128/builder.rb', line 378

def string
  return NAN_STRING if nan?
  str = infinity? ? INFINITY_STRING : create_string
  negative? ? "-#{str}" : str
end