Skip to content

Instantly share code, notes, and snippets.

@sobataro sobataro/emoji_list.rb
Last active Dec 17, 2016

Embed
What would you like to do?
prints a list of emoji, emoji with TPVS, emoji with EPVS
#! /usr/bin/env ruby
class Emoji
attr_accessor :codepoint
def initialize(codepoint)
@codepoint = codepoint
end
def to_s
[@codepoint].pack("U*")
end
def to_text_s
[@codepoint, 0xFE0E].pack("U*")
end
def to_emoji_s
[@codepoint, 0xFE0F].pack("U*")
end
def description
hex_codepoint = @codepoint.to_s(16)
"U+#{hex_codepoint} http://www.fileformat.info/info/unicode/char/#{hex_codepoint}/index.htm"
end
end
class KeycapEmoji < Emoji
def to_s
[codepoint, 0x20E3].pack("U*")
end
def to_text_s
[codepoint, 0xFE0E, 0x20E3].pack("U*")
end
def to_emoji_s
[codepoint, 0xFE0F, 0x20E3].pack("U*")
end
def description
"U+#{@codepoint.to_s(16)} U+20E3 keycap emoji"
end
end
emoji_list = []
`wget http://unicode.org/Public/emoji/4.0/emoji-data.txt -O - | grep '; Emoji #' | cut -d ' ' -f 1`.each_line do |line|
if line.include?('..')
array = line.split('..').map { |e| e.hex }
(array.first..array.last).each { |c| emoji_list << c }
else
emoji_list << line.hex
end
end
emoji_list = emoji_list.map do |e|
if e <= 0x39
KeycapEmoji.new(e)
else
Emoji.new(e)
end
end
puts "# format:\n# emoji emoji_with_TPVS emoji_with_EPVS # description\n\n"
emoji_list.map { |e| puts "#{e.to_s} #{e.to_text_s} #{e.to_emoji_s} # #{e.description}" }
puts "\n# total: #{emoji_list.count}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.