attribute_normalizer icon indicating copy to clipboard operation
attribute_normalizer copied to clipboard

Shorthand for manual normalization

Open AlexeyMK opened this issue 10 years ago • 3 comments

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!

AlexeyMK avatar Jul 18 '14 21:07 AlexeyMK

Great feature request. I have done something similar myself a few times when dealing with legacy data.

mdeering avatar Jul 19 '14 05:07 mdeering

@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.

AlexeyMK avatar Jul 19 '14 09:07 AlexeyMK

:+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.

joshminnie avatar Apr 21 '15 21:04 joshminnie