Module: Emoji
Defined Under Namespace
Classes: Character
Instance Method Summary collapse
- #all ⇒ Object
-
#create(name) ⇒ Object
Public: Initialize an Emoji::Character instance and yield it to the block.
- #data_file ⇒ Object
-
#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.
-
#find_by_alias(name) ⇒ Object
Public: Find an emoji by its aliased name.
-
#find_by_unicode(unicode) ⇒ Object
Public: Find an emoji by its unicode character.
Instance Method Details
#all ⇒ Object
14 15 16 17 18 19 |
# File 'lib/emoji.rb', line 14 def all return @all if defined? @all @all = [] parse_data_file @all 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.
23 24 25 26 27 |
# File 'lib/emoji.rb', line 23 def create(name) emoji = Emoji::Character.new(name) self.all << edit_emoji(emoji) { yield emoji if block_given? } emoji end |
#data_file ⇒ Object
10 11 12 |
# File 'lib/emoji.rb', line 10 def data_file File.('../../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.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/emoji.rb', line 31 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.
48 49 50 |
# File 'lib/emoji.rb', line 48 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.
53 54 55 |
# File 'lib/emoji.rb', line 53 def find_by_unicode(unicode) unicodes_index[unicode] || unicodes_index[unicode.sub(SKIN_TONE_RE, "")] end |