Class: Remi::Transform::ValidateEmail
- Inherits:
-
Remi::Transform
- Object
- Remi::Transform
- Remi::Transform::ValidateEmail
- Defined in:
- lib/remi/transform.rb
Overview
Public: Checks to see if an email validates against a regex (imperfect) and will substitute it with some value if not.
substitute - The value used to substitute for an invalid email. Can use a proc
that accepts the value of the invalid email
Examples:
ValidateEmail.new('[email protected]').to_proc.call('uhave.email') #=> '[email protected]'
ValidateEmail.new(->(v) { "#{SecureRandom.uuid}@example.com" }).to_proc.call('uhave.email') #=> '[email protected]'
Instance Attribute Summary
Attributes inherited from Remi::Transform
#multi_args, #source_metadata, #target_metadata
Instance Method Summary collapse
-
#initialize(substitute = '', *args, **kargs, &block) ⇒ ValidateEmail
constructor
A new instance of ValidateEmail.
- #transform(value) ⇒ Object
Methods inherited from Remi::Transform
Constructor Details
#initialize(substitute = '', *args, **kargs, &block) ⇒ ValidateEmail
Returns a new instance of ValidateEmail.
446 447 448 449 |
# File 'lib/remi/transform.rb', line 446 def initialize(substitute='', *args, **kargs, &block) super @substitute = substitute end |
Instance Method Details
#transform(value) ⇒ Object
451 452 453 454 455 456 457 458 459 460 |
# File 'lib/remi/transform.rb', line 451 def transform(value) value = value || '' if value.match(/^[A-Z0-9._%+-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,}$/i) value elsif @substitute.respond_to? :call @substitute.call value else @substitute end end |