Skip to content

Instantly share code, notes, and snippets.

@alexbaldwin
Created January 10, 2016 01:49
Show Gist options
  • Save alexbaldwin/cc90648fc1a67cd5762f to your computer and use it in GitHub Desktop.
Save alexbaldwin/cc90648fc1a67cd5762f to your computer and use it in GitHub Desktop.
Twitter Emoji Extractor
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