Skip to content

Instantly share code, notes, and snippets.

@sobataro
Last active December 17, 2016 16:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sobataro/436173433c0db9ae22bd578e9d376b77 to your computer and use it in GitHub Desktop.
Save sobataro/436173433c0db9ae22bd578e9d376b77 to your computer and use it in GitHub Desktop.
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