@@ -43,13 +43,20 @@ def add_alias(name)
4343 # Raw Unicode string for an emoji. Nil if emoji is non-standard.
4444 def raw ( ) unicode_aliases . first end
4545
46- # Raw Unicode strings for each skin tone variant of this emoji.
46+ # Raw Unicode strings for each skin tone variant of this emoji. The result is an empty array
47+ # unless the emoji supports skin tones.
48+ #
49+ # Note: for emojis that depict multiple people (e.g. couples or families), this will not produce
50+ # every possible permutation of skin tone per person.
4751 def raw_skin_tone_variants
4852 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
53+ raw_normalized = raw . sub ( VARIATION_SELECTOR_16 , "" )
54+ idx = raw_normalized . index ( ZERO_WIDTH_JOINER )
5155 SKIN_TONES . map do |modifier |
52- if idx
56+ if raw_normalized == PEOPLE_HOLDING_HANDS
57+ # special case to apply the modifier to both persons
58+ raw_normalized [ 0 ...idx ] + modifier + raw_normalized [ idx ..nil ] + modifier
59+ elsif idx
5360 # insert modifier before zero-width joiner
5461 raw_normalized [ 0 ...idx ] + modifier + raw_normalized [ idx ..nil ]
5562 else
@@ -97,7 +104,11 @@ def image_filename
97104 end
98105
99106 private
100-
107+
108+ VARIATION_SELECTOR_16 = "\u{fe0f} " . freeze
109+ ZERO_WIDTH_JOINER = "\u{200d} " . freeze
110+ PEOPLE_HOLDING_HANDS = "\u{1f9d1} \u{200d} \u{1f91d} \u{200d} \u{1f9d1} " . freeze
111+
101112 SKIN_TONES = [
102113 "\u{1F3FB} " , # light skin tone
103114 "\u{1F3FC} " , # medium-light skin tone
@@ -106,7 +117,7 @@ def image_filename
106117 "\u{1F3FF} " , # dark skin tone
107118 ]
108119
109- private_constant :SKIN_TONES
120+ private_constant :VARIATION_SELECTOR_16 , :ZERO_WIDTH_JOINER , :PEOPLE_HOLDING_HANDS , : SKIN_TONES
110121
111122 def default_image_filename
112123 if custom?
0 commit comments