Module: Mongoid::Extensions::BigDecimal::ClassMethods

Defined in:
build/mongoid-6.1/lib/mongoid/extensions/big_decimal.rb

Instance Method Summary collapse

Instance Method Details

#demongoize(object) ⇒ BigDecimal?

Convert the object from its mongo friendly ruby type to this type.

Examples:

Demongoize the object.

Object.demongoize(object)

Parameters:

  • object (Object)

    The object to demongoize.

Returns:

  • (BigDecimal, nil)

    A BigDecimal derived from the object or nil.

Since:

  • 3.0.0



55
56
57
# File 'build/mongoid-6.1/lib/mongoid/extensions/big_decimal.rb', line 55

def demongoize(object)
  object && object.numeric? ? ::BigDecimal.new(object.to_s) : nil
end

#mongoize(object) ⇒ String?

Mongoize an object of any type to how it’s stored in the db as a String.

Examples:

Mongoize the object.

BigDecimal.mongoize(123)

Parameters:

  • object (Object)

    The object to Mongoize

Returns:

  • (String, nil)

    A String representing the object or nil.

Since:

  • 3.0.7



69
70
71
# File 'build/mongoid-6.1/lib/mongoid/extensions/big_decimal.rb', line 69

def mongoize(object)
  object && object.numeric? ? object.to_s : nil
end