@@ -11,6 +11,11 @@ def self.hex_inspect(str)
1111 # True if the emoji is not a standard Emoji character.
1212 def custom? ( ) !raw end
1313
14+ # True if the emoji supports Fitzpatrick scale skin tone modifiers
15+ def skin_tones? ( ) @skin_tones end
16+
17+ attr_writer :skin_tones
18+
1419 # A list of names uniquely referring to this emoji.
1520 attr_reader :aliases
1621
@@ -38,6 +43,21 @@ def add_alias(name)
3843 # Raw Unicode string for an emoji. Nil if emoji is non-standard.
3944 def raw ( ) unicode_aliases . first end
4045
46+ # Raw Unicode strings for each skin tone variant of this emoji.
47+ def raw_skin_tone_variants
48+ return [ ] if custom? || !skin_tones?
49+ raw_normalized = raw . sub ( "\u{fe0f} " , "" ) # strip VARIATION_SELECTOR_16
50+ idx = raw_normalized . index ( "\u{200d} " ) # detect zero-width joiner
51+ SKIN_TONES . map do |modifier |
52+ if idx
53+ # insert modifier before zero-width joiner
54+ raw_normalized [ ...idx ] + modifier + raw_normalized [ idx ..]
55+ else
56+ raw_normalized + modifier
57+ end
58+ end
59+ end
60+
4161 def add_unicode_alias ( str )
4262 unicode_aliases << str
4363 end
@@ -54,6 +74,7 @@ def initialize(name)
5474 @aliases = Array ( name )
5575 @unicode_aliases = [ ]
5676 @tags = [ ]
77+ @skin_tones = false
5778 end
5879
5980 def inspect
@@ -76,6 +97,16 @@ def image_filename
7697 end
7798
7899 private
100+
101+ SKIN_TONES = [
102+ "\u{1F3FB} " , # light skin tone
103+ "\u{1F3FC} " , # medium-light skin tone
104+ "\u{1F3FD} " , # medium skin tone
105+ "\u{1F3FE} " , # medium-dark skin tone
106+ "\u{1F3FF} " , # dark skin tone
107+ ]
108+
109+ private_constant :SKIN_TONES
79110
80111 def default_image_filename
81112 if custom?
0 commit comments