Class: BSON::Decimal128::Builder::FromString 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 parsing a String into Decimal128 high and low bits.

Since:

  • 4.2.0

Constant Summary collapse

NAN_REGEX =

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.

Regex matching a string representing NaN.

Returns:

  • (Regex)

    A regex matching a NaN string.

Since:

  • 4.2.0

/^(\-)?(S)?NaN$/i
INFINITY_REGEX =

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.

Regex matching a string representing positive or negative Infinity.

Returns:

  • (Regex)

    A regex matching a positive or negative Infinity string.

Since:

  • 4.2.0

/^(\+|\-)?Inf(inity)?$/i
SIGNIFICAND_WITH_LEADING_ZEROS_REGEX =

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.

Regex for the fraction, including leading zeros.

Returns:

  • (Regex)

    The regex for matching the fraction, including leading zeros.

Since:

  • 4.2.0

/(0*)(\d+)/
SIGN_AND_DIGITS_REGEX =

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.

Regex for separating a negative sign from the significands.

Returns:

  • (Regex)

    The regex for separating a sign from significands.

Since:

  • 4.2.0

/^(\-)?(\S+)/
SCIENTIFIC_EXPONENT_REGEX =

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.

Regex matching a scientific exponent.

Returns:

  • (Regex)

    A regex matching E, e, E+, e+.

Since:

  • 4.2.0

/E\+?/i
TRAILING_ZEROS_REGEX =

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.

Regex for capturing trailing zeros.

Since:

  • 4.2.0

/[1-9]*(0+)$/
VALID_DECIMAL128_STRING_REGEX =

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.

Regex for a valid decimal128 string format.

Returns:

  • (Regex)

    The regex for a valid decimal128 string.

Since:

  • 4.2.0

/^[\-\+]?(\d+(\.\d*)?|\.\d+)(E[\-\+]?\d+)?$/i

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ FromString

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 FromString Builder object.

Examples:

Create the FromString builder.

Builder::FromString.new(string)

Parameters:

  • string (String)

    The string to create a Decimal128 from.

Since:

  • 4.2.0



169
170
171
# File 'lib/bson/decimal128/builder.rb', line 169

def initialize(string)
  @string = string
end

Instance Method Details

#bitsArray

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.

Get the bits representing the Decimal128 that the string corresponds to.

Examples:

Get the bits for the Decimal128 object created from the string.

builder.bits

Returns:

  • (Array)

    Tuple of the low and high bits.

Since:

  • 4.2.0



181
182
183
184
185
186
187
188
# File 'lib/bson/decimal128/builder.rb', line 181

def bits
  if special?
    to_special_bits
  else
    validate_format!
    to_bits
  end
end