Created
June 11, 2012 03:26
-
-
Save no6v/2908357 to your computer and use it in GitHub Desktop.
named_emoji decoder
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 "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