Last active
August 29, 2015 14:10
-
-
Save KamilLelonek/af7300d6c880bbd17a2b to your computer and use it in GitHub Desktop.
GravatarHelper module to be mixed in any class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'digest/md5' | |
module GravatarHelper | |
def gravatar_for_email(email) | |
"#{gravatar_endpoint}#{hash_for_email(email)}" | |
end | |
def hash_for_email(email) | |
Digest::MD5.hexdigest(email) | |
end | |
def gravatar_endpoint | |
'http://www.gravatar.com/avatar/' | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[0] (pry) main: 0> puts User.new('[email protected]').gravatar | |
=> 'http://www.gravatar.com/avatar/b58996c504c5638798eb6b511e6f49af' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User | |
include GravatarHelper | |
def initialize(email) | |
@email = email | |
end | |
def gravatar | |
gravatar_for_email @email | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment