class ParamsReady::Value::FormattedDecimalCoder

Constants

EU
US

Public Class Methods

coerce(value, context) click to toggle source
# 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