Giter Club home page Giter Club logo

canonical-emails's Introduction

CanonicalEmails

Gem Version Build Status Dependency Status Code Climate

Combine email validation and transformations to produce canonical email addresses. For example, parse and transform Donald Duck <[email protected]> into [email protected], for @gmail.com addresses only. Patches instances of Mail::Address.

Install

Add canonical-emails to your Gemfile.

gem 'canonical-emails'

Use

class User
  include CanonicalEmails::Extensions

  attr_accessor :email
  canonical_email :email, CanonicalEmails::GMail
end

user = User.new
user.email = "Donald Duck <[email protected]>"
user.canonical_email.class # Mail::Address
user.canonical_email.to_s # "Donald Duck <[email protected]>"
user.canonical_email.address # "[email protected]"

Transform

CanonicalEmails::Downcase

Replaces the address and domain portion of the email by its lowercase equivalent.

email = CanonicalEmails::Downcase.transform("Donald Duck <[email protected]>")
email.to_s # "Donald Duck <[email protected]>"
email.address # "[email protected]"

CanonicalEmails::GMail

Gmail.com e-mail addresses ignore periods and aren't case-sensitive. The canonical version removes them and changes the address portion to lowercase.

email = CanonicalEmails::GMail.transform("Donald Duck <[email protected]>")
email.to_s # "Donald Duck <[email protected]>"
email.local # "donaldduck"
email.address # "[email protected]"

Multiple Transformations

Combine multiple transformations, executed from left to right.

canonical_email :email, CanonicalEmails::GMail, CanonicalEmails::...

Custom Transformations

A transformation is a module that has a single transform method that returns a Mail::Address instance. This library patches internal methods of the Mail::Address class.

module CanonicalEmails
  module ReverseName
    def self.transform(value)
      Mail::Address.new(value).tap do |email|
        email.instance_eval do
          def name
            super.reverse
          end
        end
      end
    end
  end
end

email = CanonicalEmails::ReverseName.transform("Donald Duck <[email protected]>")
email.name # "kcuD dlanoD"

Contribute

See CONTRIBUTING.

Copyright and License

Copyright Daniel Doubrovkine and Contributors, Artsy, 2013-2014

MIT License

canonical-emails's People

Contributors

dblock avatar

Stargazers

 avatar joshmn avatar Igor Zubkov avatar Juanjo Seijas avatar Denis Defreyne avatar Dan Simmons avatar Shaheen Georgee avatar Rusty Meadows avatar Grégory Horion avatar Jakub Švehla avatar Rimenes Ribeiro avatar Alex Semyonov avatar Zach avatar Adam Shannon avatar Larry Fox avatar Jacky Alciné avatar Dan avatar Orion Montoya avatar Rohit Mishra avatar Ben Firshman avatar William Pramana avatar Mark Tran avatar Matt Hamilton avatar

Watchers

 avatar James Cloos avatar  avatar

Forkers

jdpopkin

canonical-emails's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.