attribute_normalizer
attribute_normalizer copied to clipboard
Shorthand for manual normalization
A quick little method I wrote for myself to be able to manually trigger a test.
Usage
AttributeNormalizer.normalize(:phone, "555-123-5123 ")
> 5551235123
Implementation
module AttributeNormalizer
def self.normalize(normalizer_sym, value)
configuration.normalizers[normalizer_sym].normalize(value)
end
end
May be worth adding a slightly more robust method to the library itself.
Thanks for the good work, @mdeering!
Great feature request. I have done something similar myself a few times when dealing with legacy data.
@mdeering - it turned out that for non-custom normalizers, I had to use .call
instead of .normalize
at the end. I implemented a currency normalizer largely by copy-pasting from the README - so, that should be a bit more consistent.
:+1:
I have found myself doing this a lot since we've added the gem to our project in migrations coming from a legacy database. Would love to see this in the gem itself.