Skip to content

Commit

Permalink
Move utility functions to emoji.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
meyer committed Oct 24, 2017
1 parent 4ae3ab3 commit 4348a17
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion emoji-db
Submodule emoji-db updated 1278 files
26 changes: 21 additions & 5 deletions emoji.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,27 @@
require 'optparse'
require 'json'
require 'shellwords'
require './emoji-db/utils.rb'
require 'pathname'

def codepoints_to_ruby(arr); arr.map(&:to_i).int_to_hex.map {|d| "\\u{#{d}}"}.join(''); end
def codepoints_to_emoji(arr); arr.map(&:to_i).pack('U*'); end
class Integer
def to_unicode
self.to_s(16).rjust(4, '0')
end
end

class Array
def to_ruby
self.map(&:to_i).int_to_hex.map {|d| "\\u{#{d}}"}.join('')
end

def int_to_hex
self.map {|item| item.is_a?(Numeric) ? item.to_unicode : item.to_s}
end

def to_emoji
self.map(&:to_i).pack('U*')
end
end

PWD = Pathname.new File.expand_path(File.dirname(__FILE__))
EMOJI_DB_PATH = PWD.join('./emoji-db/')
Expand Down Expand Up @@ -137,8 +153,8 @@ def codepoints_to_emoji(arr); arr.map(&:to_i).pack('U*'); end

emojilib_name = emoji['emojilib_name'] ? ":#{emoji['emojilib_name']}:" : ''

unicode_txt = codepoints_to_emoji(codepoints)
ruby_txt = codepoints_to_ruby(codepoints)
unicode_txt = codepoints.to_emoji
ruby_txt = codepoints.to_ruby

{
:arg => unicode_txt,
Expand Down
Binary file modified icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4348a17

Please sign in to comment.