Handling cases when , used instead of . more elegantly

This commit is contained in:
Sam Lown 2010-10-23 20:59:24 +02:00
parent ef6f54d966
commit e8d7af9896
3 changed files with 18 additions and 1 deletions

View file

@ -79,7 +79,7 @@ module CouchRest
# Match numeric string
def typecast_to_numeric(value, method)
if value.respond_to?(:to_str)
if value.to_str =~ /\A(-?(?:0|[1-9]\d*)(?:\.\d+)?|(?:\.\d+))\z/
if value.gsub(/,/, '.').gsub(/\.(?!\d*\Z)/, '').to_str =~ /\A(-?(?:0|[1-9]\d*)(?:\.\d+)?|(?:\.\d+))\z/
$1.send(method)
else
value