Module: Emoji
Defined Under Namespace
Classes: Character
Constant Summary collapse
- NotFound =
Class.new(IndexError)
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
- #find_by_unicode(unicode) ⇒ Object
- #images_path ⇒ Object
Instance Method Details
#all ⇒ Object
17 18 19 20 21 22 |
# File 'lib/emoji.rb', line 17 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.
26 27 28 29 30 |
# File 'lib/emoji.rb', line 26 def create(name) emoji = Emoji::Character.new(name) self.all << edit_emoji(emoji) { yield emoji if block_given? } emoji end |
#data_file ⇒ Object
9 10 11 |
# File 'lib/emoji.rb', line 9 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.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/emoji.rb', line 34 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
50 51 52 53 54 55 56 |
# File 'lib/emoji.rb', line 50 def find_by_alias(name) names_index.fetch(name) { if block_given? then yield name else raise NotFound, "Emoji not found by name: %s" % name.inspect end } end |
#find_by_unicode(unicode) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/emoji.rb', line 58 def find_by_unicode(unicode) unicodes_index.fetch(unicode) { if block_given? then yield unicode else raise NotFound, "Emoji not found from unicode: %s" % Emoji::Character.hex_inspect(unicode) end } end |
#images_path ⇒ Object
13 14 15 |
# File 'lib/emoji.rb', line 13 def images_path File.("../../images", __FILE__) end |