Sha256: c1e2c1b56d8654eb38ee22c5b161c960e70f3530189c0b5bbf7e479fb48115f2
Contents?: true
Size: 1.19 KB
Versions: 1
Compression:
Stored size: 1.19 KB
Contents
require 'emoji_data/version' require 'emoji_data/emoji_char' require 'json' module EmojiData GEM_ROOT = File.join(File.dirname(__FILE__), '..') RAW_JSON = IO.read(File.join(GEM_ROOT, 'vendor/emoji-data/emoji.json')) EMOJI_MAP = JSON.parse( RAW_JSON ) EMOJI_CHARS = EMOJI_MAP.map { |em| EmojiChar.new(em) } def self.all EMOJI_CHARS end def self.chars @chars ||= EMOJI_CHARS.map(&:char) end def self.codepoints @codepoints ||= EMOJI_CHARS.map(&:unified) end def self.char_to_unified(char) char.codepoints.to_a.map {|i| i.to_s(16).rjust(4,'0')}.join('-').upcase end def self.unified_to_char(cp) find_by_unified(cp).char end def self.find_by_unified(cp) EMOJI_CHARS.detect { |ec| ec.unified == cp.upcase } end def self.find_by_name(name) # self.all.select { |char| char.name.include? name.upcase } self.find_by_value(:name, name.upcase) end def self.find_by_short_name(short_name) # self.all.select { |char| char.short_name.include? name.downcase } self.find_by_value(:short_name, short_name.downcase) end protected def self.find_by_value(field,value) self.all.select { |char| char.send(field).include? value } end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
emoji_data-0.0.1 | lib/emoji_data.rb |