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.freeze
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.freeze
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+)/.freeze
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+)/.freeze
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.freeze
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+)$/.freeze
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.freeze

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



163
164
165
# File 'lib/bson/decimal128/builder.rb', line 163

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



175
176
177
178
179
180
181
182
# File 'lib/bson/decimal128/builder.rb', line 175

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