Class: Castkit::Types::Float

Inherits:
Base
  • Object
show all
Defined in:
lib/castkit/types/float.rb

Overview

Type definition for :integer attributes.

Handles deserialization from raw input (e.g., strings, floats) to Float, applies optional numeric validation rules (e.g., min, max), and returns the value unchanged during serialization.

This class is used internally by Castkit when an attribute is defined with:

`integer :count`

Instance Method Summary collapse

Methods inherited from Base

cast!, deserialize, serialize, validate!

Instance Method Details

#deserialize(value) ⇒ Float

Deserializes the input value to an Float.

Parameters:

  • value (Object)

Returns:



21
22
23
# File 'lib/castkit/types/float.rb', line 21

def deserialize(value)
  value.to_f
end

#serialize(value) ⇒ Float

Serializes the Float value.

Parameters:

Returns:



29
30
31
# File 'lib/castkit/types/float.rb', line 29

def serialize(value)
  value
end

#validate!(value, options: {}, context: {}) ⇒ void

This method returns an undefined value.

Validates the Float value using Castkit’s FloatValidator.

Supports options like min: and max:.

Parameters:

  • value (Object)
  • options (Hash) (defaults to: {})

    validation options

  • context (Symbol, String) (defaults to: {})

    attribute context for error messages



41
42
43
# File 'lib/castkit/types/float.rb', line 41

def validate!(value, options: {}, context: {})
  Castkit::Validators::FloatValidator.call(value, options: options, context: context)
end