EmailTypo

Travis-CI Code Climate Test Coverage Gem Gem

EmailTypo is a Ruby gem that gives you an easy, tested method that fixes email typos.

As an example: A user with the email "[email protected]" accidentally enters in "[email protected]", EmailTypo will fix it automatically.

EmailTypo is concerned with incorrectly-entered data (email provider names, TLDs), not with evaluating whether a particular domain is valid, or whether a particular email address is legitimate. (That is, it's focused on fixing the part that comes after the "@" in the email address.) It works really well for helping you — and your users — when they accidentally type something in wrong.

NOTE: This is based on https://github.com/charliepark/fat_fingers, but without polluting the String class and with easier extension support.

Installation

Add this line to your application's Gemfile:

gem "email_typo"

And then execute:

$ bundle

Or install it yourself as:

$ gem install email_typo

Usage

To fix any typos, just use EmailTypo.fix(email).

EmailTypo.fix("[email protected]")
#=> "[email protected]"

To add/change the processors, add any object that responds to #call(email) to EmailTypo.default_processors. The following example adds a processor for .uol.com.br, a Brazilian email provider:

EmailTypo.default_processors << lambda do |email|
  email.gsub(/@uol\.com(\..*?)?/, "@uol.com.br")
end

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/fnando/email_typo. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.