@@ -43,13 +43,20 @@ def add_alias(name)
43
43
# Raw Unicode string for an emoji. Nil if emoji is non-standard.
44
44
def raw ( ) unicode_aliases . first end
45
45
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.
47
51
def raw_skin_tone_variants
48
52
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 )
51
55
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
53
60
# insert modifier before zero-width joiner
54
61
raw_normalized [ 0 ...idx ] + modifier + raw_normalized [ idx ..nil ]
55
62
else
@@ -97,7 +104,11 @@ def image_filename
97
104
end
98
105
99
106
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
+
101
112
SKIN_TONES = [
102
113
"\u{1F3FB} " , # light skin tone
103
114
"\u{1F3FC} " , # medium-light skin tone
@@ -106,7 +117,7 @@ def image_filename
106
117
"\u{1F3FF} " , # dark skin tone
107
118
]
108
119
109
- private_constant :SKIN_TONES
120
+ private_constant :VARIATION_SELECTOR_16 , :ZERO_WIDTH_JOINER , :PEOPLE_HOLDING_HANDS , : SKIN_TONES
110
121
111
122
def default_image_filename
112
123
if custom?
0 commit comments