class Emoji::Character
Constants
- PEOPLE_HOLDING_HANDS
- SKIN_TONES
- VARIATION_SELECTOR_16
- ZERO_WIDTH_JOINER
Attributes
A list of names uniquely referring to this emoji.
The category for this emoji as per Appleās character palette
The Unicode description text
The iOS version where this emoji first debuted
A list of Unicode strings that uniquely refer to this emoji.
The Unicode spec version where this emoji first debuted
Public Class Methods
Inspect individual Unicode characters in a string by dumping its codepoints in hexadecimal format.
# File lib/emoji/character.rb, line 7 def self.hex_inspect(str) str.codepoints.map { |c| c.to_s(16).rjust(4, '0') }.join('-') end
# File lib/emoji/character.rb, line 80 def initialize(name) @aliases = Array(name) @unicode_aliases = [] @tags = [] @skin_tones = false end
Public Instance Methods
# File lib/emoji/character.rb, line 36 def add_alias(name) aliases << name end
# File lib/emoji/character.rb, line 76 def add_tag(tag) tags << tag end
# File lib/emoji/character.rb, line 68 def add_unicode_alias(str) unicode_aliases << str end
True if the emoji is not a standard Emoji
character.
# File lib/emoji/character.rb, line 12 def custom?() !raw end
# File lib/emoji/character.rb, line 92 def hex_inspect self.class.hex_inspect(raw) end
# File lib/emoji/character.rb, line 98 def image_filename if defined? @image_filename @image_filename else default_image_filename end end
# File lib/emoji/character.rb, line 87 def inspect hex = '(%s)' % hex_inspect unless custom? %(#<#{self.class.name}:#{name}#{hex}>) end
# File lib/emoji/character.rb, line 34 def name() aliases.first end
Raw Unicode string for an emoji. Nil if emoji is non-standard.
# File lib/emoji/character.rb, line 44 def raw() unicode_aliases.first end
Raw Unicode strings for each skin tone variant of this emoji. The result is an empty array unless the emoji supports skin tones.
Note: for emojis that depict multiple people (e.g. couples or families), this will not produce every possible permutation of skin tone per person.
# File lib/emoji/character.rb, line 51 def raw_skin_tone_variants return [] if custom? || !skin_tones? raw_normalized = raw.sub(VARIATION_SELECTOR_16, "") idx = raw_normalized.index(ZERO_WIDTH_JOINER) SKIN_TONES.map do |modifier| if raw_normalized == PEOPLE_HOLDING_HANDS # special case to apply the modifier to both persons raw_normalized[0...idx] + modifier + raw_normalized[idx..nil] + modifier elsif idx # insert modifier before zero-width joiner raw_normalized[0...idx] + modifier + raw_normalized[idx..nil] else raw_normalized + modifier end end end
True if the emoji supports Fitzpatrick scale skin tone modifiers
# File lib/emoji/character.rb, line 15 def skin_tones?() @skin_tones end
Private Instance Methods
# File lib/emoji/character.rb, line 122 def default_image_filename if custom? '%s.png' % name else hex_name = hex_inspect.gsub(/-(fe0f|200d)\b/, '') 'unicode/%s.png' % hex_name end end