Created
October 4, 2014 19:16
-
-
Save joemsak/06fe11ad6c02efccc6c3 to your computer and use it in GitHub Desktop.
This file contains 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 ShortUrl | |
def self.create(url) | |
url.shortened_hash = first_five_of_sha256(url) | |
url.save | |
end | |
def self.for(url) | |
ENV['HOSTNAME'] + url.shortened_hash | |
end | |
private | |
def self.first_five_of_sha256(url) | |
digest = Digest::SHA256.hexdigest(url.long) | |
digest[0..4] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment