Module: Emoji

Extended by:
Emoji
Included in:
Emoji
Defined in:
lib/emoji.rb,
lib/emoji/cli.rb,
lib/emoji/character.rb,
lib/emoji/extractor.rb

Defined Under Namespace

Modules: CLI Classes: Character, Extractor

Instance Method Summary collapse

Instance Method Details

#allObject



20
21
22
23
24
25
# File 'lib/emoji.rb', line 20

def all
  return @all if defined? @all
  @all = []
  parse_data_file
  @all
end

#apple_paletteObject



27
28
29
30
31
32
33
34
35
36
# File 'lib/emoji.rb', line 27

def apple_palette
  return @apple_palette if defined? @apple_palette
  data = File.open(apple_palette_file, 'r:UTF-8') { |f| JSON.parse(f.read) }
  @apple_palette = data.fetch('EmojiDataArray').each_with_object({}) do |group, all|
    title = group.fetch('CVDataTitle').split('-', 2)[1]
    all[title] = group.fetch('CVCategoryData').fetch('Data').split(',').map do |raw|
      TEXT_GLYPHS.include?(raw) ? raw + VARIATION_SELECTOR_16 : raw
    end
  end
end

#apple_palette_fileObject



12
13
14
# File 'lib/emoji.rb', line 12

def apple_palette_file
  File.expand_path('../../db/Category-Emoji.json', __FILE__)
end

#create(name) ⇒ Object

Public: Initialize an Emoji::Character instance and yield it to the block. The character is added to the ‘Emoji.all` set.



40
41
42
43
44
# File 'lib/emoji.rb', line 40

def create(name)
  emoji = Emoji::Character.new(name)
  self.all << edit_emoji(emoji) { yield emoji if block_given? }
  emoji
end

#data_fileObject



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

def data_file
  File.expand_path('../../db/emoji.json', __FILE__)
end

#edit_emoji(emoji) {|emoji| ... } ⇒ Object

Public: Yield an emoji to the block and update the indices in case its aliases or unicode_aliases lists changed.

Yields:

  • (emoji)


48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/emoji.rb', line 48

def edit_emoji(emoji)
  @names_index ||= Hash.new
  @unicodes_index ||= Hash.new

  yield emoji

  emoji.aliases.each do |name|
    @names_index[name] = emoji
  end
  emoji.unicode_aliases.each do |unicode|
    @unicodes_index[unicode] = emoji
  end

  emoji
end

#find_by_alias(name) ⇒ Object

Public: Find an emoji by its aliased name. Return nil if missing.



65
66
67
# File 'lib/emoji.rb', line 65

def find_by_alias(name)
  names_index[name]
end

#find_by_unicode(unicode) ⇒ Object

Public: Find an emoji by its unicode character. Return nil if missing.



70
71
72
# File 'lib/emoji.rb', line 70

def find_by_unicode(unicode)
  unicodes_index[unicode]
end

#images_pathObject



16
17
18
# File 'lib/emoji.rb', line 16

def images_path
  File.expand_path("../../images", __FILE__)
end