Class: Mongoid::Fields::Serializable::Float

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Fields::Serializable
Defined in:
lib/mongoid/fields/serializable/float.rb

Overview

Defines the behaviour for float fields.

Instance Attribute Summary

Attributes included from Mongoid::Fields::Serializable

#default_val, #label, #localize, #name, #options

Instance Method Summary collapse

Methods included from Mongoid::Fields::Serializable

#constraint, #deserialize, #eval_default, #localized?, #metadata, #object_id_field?, #type, #versioned?

Instance Method Details

#serialize(object) ⇒ Float

Serialize the object from the type defined in the model to a MongoDB compatible object to store.

Examples:

Serialize the field.

field.serialize(object)

Parameters:

  • object (Object)

    The object to cast.

Returns:

  • (Float)

    The converted float.

Since:

  • 2.1.0



21
22
23
24
25
26
27
28
# File 'lib/mongoid/fields/serializable/float.rb', line 21

def serialize(object)
  return nil if object.blank?
  begin
    Float(object)
  rescue ArgumentError => e
    object
  end
end