Sha256: 103c22f5ffda9e41f288c65f967a9e751c07c31b942ea0b0cc6b846364c411e6

Contents?: true

Size: 969 Bytes

Versions: 4

Compression:

Stored size: 969 Bytes

Contents

require 'forwardable'

module Emoji
  class Index
    extend Forwardable

    attr_reader :unicode_moji_regex

    def_delegator :@emoji_by_moji, :[], :find_by_moji
    def_delegator :@emoji_by_name, :[], :find_by_name
    def_delegator :@emoji_by_unicode, :[], :find_by_unicode

    def initialize(emoji_list=nil)
      emoji_list ||= begin
        emoji_json = File.read(File.absolute_path(File.dirname(__FILE__) + '/../../config/index.json'))
        JSON.parse(emoji_json)
      end

      @emoji_by_name = {}
      @emoji_by_moji = {}
      @emoji_by_unicode = {}

      emoji_list.each do |emoji_hash|
        name = emoji_hash['name']
        @emoji_by_name[name] = emoji_hash if name

        moji = emoji_hash['moji']
        @emoji_by_moji[moji] = emoji_hash if moji

        unicode = emoji_hash['unicode']
        @emoji_by_unicode[unicode] = emoji_hash if unicode
      end

      @unicode_moji_regex = /#{@emoji_by_moji.keys.join('|')}/
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
emoji-1.0.6 lib/emoji/index.rb
emoji-1.0.5 lib/emoji/index.rb
emoji-1.0.4 lib/emoji/index.rb
emoji-1.0.2 lib/emoji/index.rb