Class: ParamsReady::Value::FormattedDecimalCoder
- Inherits:
-
DecimalCoder
- Object
- Coder
- DecimalCoder
- ParamsReady::Value::FormattedDecimalCoder
- Defined in:
- lib/params_ready/value/custom.rb
Constant Summary collapse
- EU =
/^(\d{1,3}( \d{3})+|\d+),\d{1,2}$/.freeze
- US =
/^(\d{1,3}(,\d{3})+).\d{1,2}$/.freeze
Class Method Summary collapse
Methods inherited from DecimalCoder
Methods inherited from Coder
strict_default?, try_coerce, value_class_name
Methods included from Extensions::ClassReaderWriter
Class Method Details
.coerce(value, context) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/params_ready/value/custom.rb', line 18 def self.coerce(value, context) value = if value.is_a? String stripped = value.strip if EU.match? stripped stripped.gsub(/[ ,]/, ' ' => '', ',' => '.') elsif US.match? stripped stripped.delete(',') else stripped end else value end super end |