Add replace_dots option to CleanDecimal

This commit is contained in:
Florent 2014-03-20 14:25:56 +01:00
commit 0feae01a9c

View file

@ -156,8 +156,13 @@ class CleanDecimal(CleanText):
""" """
Get a cleaned Decimal value from an element. Get a cleaned Decimal value from an element.
""" """
def __init__(self, selector, replace_dots=True):
super(CleanDecimal, self).__init__(selector)
self.replace_dots = replace_dots
def filter(self, text): def filter(self, text):
text = super(CleanDecimal, self).filter(text) text = super(CleanDecimal, self).filter(text)
if self.replace_dots:
text = text.replace('.','').replace(',','.') text = text.replace('.','').replace(',','.')
return Decimal(re.sub(ur'[^\d\-\.]', '', text)) return Decimal(re.sub(ur'[^\d\-\.]', '', text))