Class: Emoji::Index

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(emoji_list = nil) ⇒ Index

Returns a new instance of Index.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/emoji/index.rb', line 13

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

  annotated_name_strings = @emoji_by_name.keys.map{|name| ":#{name}:" }
  @named_moji_regex = /#{ annotated_name_strings.join('|') }/
  @unicode_moji_regex = /#{ @emoji_by_moji.keys.join('|') }/
end

Instance Attribute Details

#named_moji_regexObject (readonly)

Returns the value of attribute named_moji_regex.



7
8
9
# File 'lib/emoji/index.rb', line 7

def named_moji_regex
  @named_moji_regex
end

#unicode_moji_regexObject (readonly)

Returns the value of attribute unicode_moji_regex.



7
8
9
# File 'lib/emoji/index.rb', line 7

def unicode_moji_regex
  @unicode_moji_regex
end