Class: TanukiEmoji::Db::Gemojione
- Inherits:
-
Object
- Object
- TanukiEmoji::Db::Gemojione
- Defined in:
- lib/tanuki_emoji/db/gemojione.rb
Overview
Gemojione Emoji database In order to maintain compatibility with alpha_codes that have been stored in a DB originally using the gemojione codes, we change the original gemojione code to be the primary and make the unicode version to be an alias. So instead of the alpha code being โthumbs_up` based on the unicode naming, itโs โthumbsup`, with an alias of `thumbs_up`
Constant Summary collapse
- DATA_FILE =
'vendor/gemojione/index-3.3.0.json'
- EMOJI_DIFFERENCES =
rubocop:disable Style/AsciiComments These are specific gemojione whos alpha codes map slightly differently. For example, :cow: in gemojione is ๐ฎ, while in Unicode it is ๐, which is :cow2: in gemojione. Now :cow_face: will give ๐ฎ. See gitlab.com/gitlab-org/ruby/gems/tanuki_emoji/-/merge_requests/65#note_2113986561
{ unicode: %w[๐ ๐ช ๐ ๐ ๐ ๐ ๐ โ๏ธ ๐ ๐ ๐ฐ๏ธ โ๏ธ ๐ ๐ โ๏ธ ๐], gemojione: %w[๐ ๐ซ ๐ฑ ๐ฎ ๐ถ ๐ด ๐ญ ๐ ๐ท ๐ฐ ๐ก โ ๐ฏ ๐ โ ๐ณ] }.freeze
Instance Attribute Summary collapse
-
#data_file ⇒ Object
readonly
Returns the value of attribute data_file.
Class Method Summary collapse
-
.data_file ⇒ Object
rubocop:enable Style/AsciiComments.
Instance Method Summary collapse
-
#initialize(index:, data_file: self.class.data_file) ⇒ Gemojione
constructor
A new instance of Gemojione.
- #load! ⇒ Object
Constructor Details
#initialize(index:, data_file: self.class.data_file) ⇒ Gemojione
Returns a new instance of Gemojione.
34 35 36 37 |
# File 'lib/tanuki_emoji/db/gemojione.rb', line 34 def initialize(index:, data_file: self.class.data_file) @data_file = data_file @index = index end |
Instance Attribute Details
#data_file ⇒ Object (readonly)
Returns the value of attribute data_file.
32 33 34 |
# File 'lib/tanuki_emoji/db/gemojione.rb', line 32 def data_file @data_file end |
Class Method Details
.data_file ⇒ Object
rubocop:enable Style/AsciiComments
28 29 30 |
# File 'lib/tanuki_emoji/db/gemojione.rb', line 28 def self.data_file File.(File.join(__dir__, '../../../', DATA_FILE)) end |
Instance Method Details
#load! ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/tanuki_emoji/db/gemojione.rb', line 39 def load! db = File.open(data_file, 'r:UTF-8') do |file| JSON.parse(file.read, symbolize_names: true) end db.each_value do |emoji_data| emoji = @index.find_by_codepoints(emoji_data[:moji]) # if it's not found, don't try to add something that isn't in the # Unicode set. next unless emoji if emoji.alpha_code != emoji_data[:shortname] org_alpha_code = emoji.alpha_code org_alpha_code_sym = TanukiEmoji::Character.format_name(org_alpha_code).to_sym emoji.replace_alpha_code(emoji_data[:shortname]) # rubocop:disable Style/AsciiComments # Ensure that we're not adding an alias that is part of the gemonione data. # For example, Unicode uses `sunglasses` for ๐ถ๏ธ, which is `dark_sunglasses` in gemojione. # `sunglasses` is ๐ which is `smiling_face_with_sunglasses` in Unicode. # We don't want `sunglasses` to be added as an alias of `dark_sunglasses`, because that # would interfere with `sunglasses` being the primary code for `smiling_face_with_sunglasses` # rubocop:enable Style/AsciiComments emoji.add_alias(org_alpha_code) unless db.key?(org_alpha_code_sym) || EMOJI_DIFFERENCES[:unicode].include?(emoji.codepoints) end add_emoji_data(emoji, emoji_data) @index.update(emoji) end end |