Module: AttributeNormalizer::Normalizers::FloatNormalizer
- Defined in:
- lib/attribute_normalizer/normalizers/float_normalizer.rb
Overview
Accept an input value of various types and coerce it into a float.
Valid types for coersion are: String, Numeric, and NilClass.
Options
- allow_blank
-
Will not attempt to coerce nil or ” to a float if this evaluates to a truthy value. DEFAULT: false
Notes
This normalizer does not handle negative values, or perform any rounding
Usage
AttributeNormalizer::Normalizers::FloatNormalizer.normalize(‘$1,500.00’)
Constant Summary collapse
- DEFAULTS =
{ blank: false }.freeze
Class Method Summary collapse
Class Method Details
.normalize(value, opts = {}) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/attribute_normalizer/normalizers/float_normalizer.rb', line 23 def normalize(value, opts = {}) case value when String handle_string(value, opts) when Numeric value.to_f when NilClass handle_nil(opts) else invalid_type!(value) end end |