Class: Emoji::Index

Inherits:
Object
  • Object
show all
Defined in:
lib/emoji/index.rb

Instance Method Summary collapse

Constructor Details

#initialize(emoji_list = nil) ⇒ Index


3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/emoji/index.rb', line 3

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_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
  end
  @emoji_moji_regex = /#{@emoji_by_moji.keys.join('|')}/
end

Instance Method Details

#find_by_moji(moji) ⇒ Object


22
23
24
# File 'lib/emoji/index.rb', line 22

def find_by_moji(moji)
  @emoji_by_moji[moji]
end

#find_by_name(name) ⇒ Object


26
27
28
# File 'lib/emoji/index.rb', line 26

def find_by_name(name)
  @emoji_by_name[name]
end

#unicode_moji_regexObject


30
31
32
# File 'lib/emoji/index.rb', line 30

def unicode_moji_regex
  @emoji_moji_regex
end