Class: Castkit::Types::Float
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
-
#deserialize(value) ⇒ Float
Deserializes the input value to an Float.
-
#serialize(value) ⇒ Float
Serializes the Float value.
-
#validate!(value, options: {}, context: {}) ⇒ void
Validates the Float value using Castkit’s FloatValidator.
Methods inherited from Base
cast!, deserialize, serialize, validate!
Instance Method Details
#deserialize(value) ⇒ Float
Deserializes the input value to an Float.
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.
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:`.
41 42 43 |
# File 'lib/castkit/types/float.rb', line 41 def validate!(value, options: {}, context: {}) Castkit::Validators::FloatValidator.call(value, options: , context: context) end |