On 2.7.2008, at 12.46, Benjamin Meichsner wrote:

Hey Isak,

I currently working on the same problem. In my last projects I have
workaround with an own setter for the numbers. e.g.

the active-record model
class Article
 def price=(value)
   self.price = value.to_delocalized_decimal
 end
end

and the String-class extension:

class String
 def to_delocalized_decimal
   return self if !self.is_a?(String) or self.blank?
   BigDecimal.new(string.sub(',', '.'))
 end
end

maybe this is usefull for your research-program. But i guess its better
to use extra methods to fill your database-field. In this case the
output would be also localized. e.g.

def localized_price=(value)
 self.price = value.to_delocalized_decimal
end
def localized_price
 price.to_delocalized_decimal # use another BigDecimal-extension
end

Just curious, but you do realize that to_delocalized_decimal is only defined in the String class? That has two consequences: any other object than a string will throw an exception. That's ok, if you only ever get strings as values. However, in that case (and anyway since you're defining the method in the String class) there's no idea checking whether self is a string in the to_delocalized_decimal method. self.is_a?(String) will always return true when used inside a method of the String class.

//jarkko

--
Jarkko Laine
http://jlaine.net
http://dotherightthing.com
http://www.railsecommerce.com
http://odesign.fi

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________
Railsi18n-discussion mailing list
Railsi18n-discussion@rubyforge.org
http://rubyforge.org/mailman/listinfo/railsi18n-discussion

Reply via email to