Module: ConcernsOnRails::Models::Normalizable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/concerns_on_rails/models/normalizable.rb
Constant Summary collapse
- PRESETS =
Built-in normalization presets. Each is string-safe — non-string values pass through unchanged so callers don’t have to guard themselves.
{ email: ->(v) { v.is_a?(String) ? v.strip.downcase : v }, phone: ->(v) { v.is_a?(String) ? v.gsub(/\D/, "") : v }, whitespace: ->(v) { v.is_a?(String) ? v.strip : v }, squish: ->(v) { v.is_a?(String) ? v.squish : v }, downcase: ->(v) { v.is_a?(String) ? v.downcase : v }, upcase: ->(v) { v.is_a?(String) ? v.upcase : v } }.freeze
Instance Method Summary collapse
Instance Method Details
#apply_normalizations ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/concerns_on_rails/models/normalizable.rb', line 64 def apply_normalizations self.class.normalizable_rules.each do |field, normalizer| value = self[field] next if value.nil? self[field] = normalizer.call(value) end end |