Class: ParamsReady::Value::FormattedDecimalCoder
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
format
Methods inherited from Coder
instance
Methods included from Coercion
#strict_default?, #try_coerce
value_class_name
#class_reader_writer
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
|