Class: Coercible::Coercer::Numeric
- Defined in:
- lib/coercible/coercer/numeric.rb
Overview
Base class for all numeric Coercion classes
Constant Summary
Constants inherited from Object
Object::COERCION_METHOD_REGEXP
Constants included from Options
Constants included from TypeLookup
Instance Attribute Summary
Attributes inherited from Object
Instance Method Summary collapse
-
#to_decimal(value) ⇒ BigDecimal
Coerce a BigDecimal instance from a numeric object.
-
#to_float(value) ⇒ Float
Creates a Float instance from a numeric object.
-
#to_integer(value) ⇒ Integer
Creates an Integer instance from a numeric object.
-
#to_string(value) ⇒ String
Coerce given value to String.
Methods inherited from Object
#coerced?, #initialize, #inspect, #to_array, #to_hash
Methods included from Options
#accept_options, #accepted_options, extended, #options
Methods included from TypeLookup
#determine_type, extended, #primitive
Constructor Details
This class inherits a constructor from Coercible::Coercer::Object
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Coercible::Coercer::Object
Instance Method Details
#to_decimal(value) ⇒ BigDecimal
Coerce a BigDecimal instance from a numeric object
60 61 62 |
# File 'lib/coercible/coercer/numeric.rb', line 60 def to_decimal(value) to_string(value).to_d end |
#to_float(value) ⇒ Float
Creates a Float instance from a numeric object
46 47 48 |
# File 'lib/coercible/coercer/numeric.rb', line 46 def to_float(value) value.to_f end |
#to_integer(value) ⇒ Integer
Creates an Integer instance from a numeric object
32 33 34 |
# File 'lib/coercible/coercer/numeric.rb', line 32 def to_integer(value) value.to_i end |
#to_string(value) ⇒ String
Coerce given value to String
18 19 20 |
# File 'lib/coercible/coercer/numeric.rb', line 18 def to_string(value) value.to_s end |