Created
January 10, 2016 01:49
-
-
Save alexbaldwin/cc90648fc1a67cd5762f to your computer and use it in GitHub Desktop.
Twitter Emoji Extractor
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 'twemoji' | |
require 'active_support/core_ext/string/inflections' | |
sentence = "I like chocolate" | |
words = sentence.downcase.split(/\W+/) | |
words.delete_if { |w| w.size <= 2 } | |
emojis = "" | |
words.each do |word| | |
word = word.singularize | |
word = ':' + word + ':' | |
emoji = Twemoji.find_by_text(word) | |
if emoji | |
emojis << Twemoji.render_unicode(word) | |
end | |
end | |
if emojis.size >= 1 | |
emojis << ' ' | |
end | |
p emojis |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment