Skip to content

Instantly share code, notes, and snippets.

@no6v
Created June 11, 2012 03:26
Show Gist options
  • Save no6v/2908357 to your computer and use it in GitHub Desktop.
Save no6v/2908357 to your computer and use it in GitHub Desktop.
named_emoji decoder
require "named_emoji"
Earthquake.once do
::EMOJIMOJI = NamedEmoji.emojis.each_with_object(Hash.new{|h, k| h[k] = {}}) do |(key, value), hash|
hash[value.size].update(value => ":#{key}:") if value
end
::EMOJI_RE = ::EMOJIMOJI.inject({}) do |regexps, (size, hash)|
re = case size
when 1
Regexp.new("[" + hash.keys.join + "]")
else
Regexp.union(hash.keys)
end
regexps.update(size => re)
end
end
Earthquake.init do
command :emojimoji do |m|
text = twitter.status(m[1])["text"].u
::EMOJIMOJI.keys.sort.reverse_each do |size|
text.gsub!(::EMOJI_RE[size], ::EMOJIMOJI[size])
end
puts text
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment