Module: Unicode::Emoji

Defined in:
lib/unicode/emoji.rb,
lib/unicode/emoji/index.rb,
lib/unicode/emoji/constants.rb

Constant Summary collapse

PROPERTY_NAMES =
{
  E: "Emoji",
  B: "Emoji_Modifier_Base",
  M: "Emoji_Modifier",
  C: "Emoji_Component",
  P: "Emoji_Presentation",
  X: "Extended_Pictographic",
}
EMOJI_VARIATION_SELECTOR =
0xFE0F
TEXT_VARIATION_SELECTOR =
0xFE0E
EMOJI_TAG_BASE_FLAG =
0x1F3F4
CANCEL_TAG =
0xE007F
TAGS =
[*0xE0020..0xE007E]
EMOJI_KEYCAP_SUFFIX =
0x20E3
ZWJ =
0x200D
REGIONAL_INDICATORS =
[*0x1F1E6..0x1F1FF]
EMOJI_CHAR =
INDEX[:PROPERTIES].select{ |ord, props| props.include?(:E) }.keys.freeze
EMOJI_PRESENTATION =
INDEX[:PROPERTIES].select{ |ord, props| props.include?(:P) }.keys.freeze
TEXT_PRESENTATION =
INDEX[:PROPERTIES].select{ |ord, props| props.include?(:E) && !props.include?(:P) }.keys.freeze
EMOJI_COMPONENT =
INDEX[:PROPERTIES].select{ |ord, props| props.include?(:C) }.keys.freeze
EMOJI_MODIFIER_BASES =
INDEX[:PROPERTIES].select{ |ord, props| props.include?(:B) }.keys.freeze
EMOJI_MODIFIERS =
INDEX[:PROPERTIES].select{ |ord, props| props.include?(:M) }.keys.freeze
EXTENDED_PICTOGRAPHIC =
INDEX[:PROPERTIES].select{ |ord, props| props.include?(:X) }.keys.freeze
EXTENDED_PICTOGRAPHIC_NO_EMOJI =
INDEX[:PROPERTIES].select{ |ord, props| props.include?(:X) && !props.include?(:E) }.keys.freeze
EMOJI_KEYCAPS =
INDEX[:KEYCAPS].freeze
VALID_REGION_FLAGS =
INDEX[:FLAGS].freeze
VALID_SUBDIVISIONS =
INDEX[:SD].freeze
INDEX[:TAGS].freeze
INDEX[:ZWJ].freeze
LIST =
INDEX[:LIST].freeze.each_value(&:freeze)
LIST_REMOVED_KEYS =
[
  "Smileys & People",
]
REGEX =

Matches basic singleton emoji and all kind of sequences, but restrict zwj and tag sequences to known sequences (rgi)

Regexp.compile(emoji_rgi_sequence)
REGEX_VALID =

Matches basic singleton emoji and all kind of valid sequences

Regexp.compile(emoji_valid_sequence)
REGEX_WELL_FORMED =

Matches basic singleton emoji and all kind of sequences

Regexp.compile(emoji_well_formed_sequence)
REGEX_BASIC =

Matches only basic single, non-textual emoji Ignores “components” like modifiers or simple digits

Regexp.compile(
  "(?!" + emoji_component + ")" + emoji_presentation_sequence
)
REGEX_TEXT =

Matches only basic single, textual emoji Ignores “components” like modifiers or simple digits

Regexp.compile(
  "(?!" + emoji_component + ")" + text_presentation_sequence
)
REGEX_ANY =

Matches any emoji-related codepoint - Use with caution (returns partil matches)

Regexp.compile(
  emoji_character
)
REGEX_INCLUDE_TEXT =

Combined REGEXes which also match for TEXTUAL emoji

Regexp.union(REGEX, REGEX_TEXT)
REGEX_VALID_INCLUDE_TEXT =
Regexp.union(REGEX_VALID, REGEX_TEXT)
REGEX_WELL_FORMED_INCLUDE_TEXT =
Regexp.union(REGEX_WELL_FORMED, REGEX_TEXT)
REGEX_PICTO =
Regexp.compile(
  picto
)
REGEX_PICTO_NO_EMOJI =
Regexp.compile(
  picto_no_emoji
)
VERSION =
"2.7.1"
EMOJI_VERSION =
"13.1"
CLDR_VERSION =
"38.1"
DATA_DIRECTORY =
File.expand_path(File.dirname(__FILE__) + "/../../../data/").freeze
INDEX_FILENAME =
(DATA_DIRECTORY + "/emoji.marshal.gz").freeze

Class Method Summary collapse

Class Method Details

.get_codepoint_value(char) ⇒ Object



232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# File 'lib/unicode/emoji.rb', line 232

def self.get_codepoint_value(char)
  ord = nil

  if char.valid_encoding?
    ord = char.ord
  elsif char.encoding.name == "UTF-8"
    begin
      ord = char.unpack("U*")[0]
    rescue ArgumentError
    end
  end

  if ord
    ord
  else
    raise(ArgumentError, "Unicode::Emoji must be given a valid string")
  end
end

.list(key = nil, sub_key = nil) ⇒ Object



224
225
226
227
228
229
230
# File 'lib/unicode/emoji.rb', line 224

def self.list(key = nil, sub_key = nil)
  return LIST unless key || sub_key
  if LIST_REMOVED_KEYS.include?(key)
    $stderr.puts "Warning(unicode-emoji): The category of #{key} does not exist anymore"
  end
  LIST.dig(*[key, sub_key].compact)
end

.properties(char) ⇒ Object



213
214
215
216
217
218
219
220
221
222
# File 'lib/unicode/emoji.rb', line 213

def self.properties(char)
  ord = get_codepoint_value(char)
  props = INDEX[:PROPERTIES][ord]

  if props
    props.map{ |prop| PROPERTY_NAMES[prop] }
  else
    # nothing
  end
end