Module: BSON::BigDecimal::ClassMethods

Defined in:
lib/bson/big_decimal.rb

Instance Method Summary collapse

Instance Method Details

#from_bson(buffer, **options) ⇒ BigDecimal | BSON::Decimal128

Deserialize the BigDecimal from raw BSON bytes. If the :mode option is set to BSON, this will return a BSON::Decimal128

Examples:

Get the BigDecimal from BSON.

BigDecimal.from_bson(bson)

Parameters:

  • buffer (ByteBuffer)

    The byte buffer.

  • options (Hash)

    a customizable set of options

Options Hash (**options):

  • :mode (nil | :bson)

    Decoding mode to use.

Returns:



60
61
62
63
64
65
66
67
# File 'lib/bson/big_decimal.rb', line 60

def from_bson(buffer, **options)
  dec128 = Decimal128.from_bson(buffer, **options)
  if options[:mode] == :bson
    dec128
  else
    dec128.to_d
  end
end