Class: Emoji::Character
- Inherits:
-
Object
- Object
- Emoji::Character
- Defined in:
- lib/emoji/character.rb
Instance Attribute Summary collapse
-
#aliases ⇒ Object
readonly
A list of names uniquely referring to this emoji.
-
#category ⇒ Object
The category for this emoji as per Apple’s character palette.
-
#description ⇒ Object
The Unicode description text.
- #image_filename ⇒ Object
-
#ios_version ⇒ Object
The iOS version where this emoji first debuted.
-
#skin_tones ⇒ Object
writeonly
Sets the attribute skin_tones.
-
#tags ⇒ Object
readonly
A list of tags associated with an emoji.
-
#unicode_aliases ⇒ Object
readonly
A list of Unicode strings that uniquely refer to this emoji.
-
#unicode_version ⇒ Object
The Unicode spec version where this emoji first debuted.
Class Method Summary collapse
-
.hex_inspect(str) ⇒ Object
Inspect individual Unicode characters in a string by dumping its codepoints in hexadecimal format.
Instance Method Summary collapse
- #add_alias(name) ⇒ Object
- #add_tag(tag) ⇒ Object
- #add_unicode_alias(str) ⇒ Object
-
#custom? ⇒ Boolean
True if the emoji is not a standard Emoji character.
- #hex_inspect ⇒ Object
-
#initialize(name) ⇒ Character
constructor
A new instance of Character.
- #inspect ⇒ Object
- #name ⇒ Object
-
#raw ⇒ Object
Raw Unicode string for an emoji.
-
#raw_skin_tone_variants ⇒ Object
Raw Unicode strings for each skin tone variant of this emoji.
-
#skin_tones? ⇒ Boolean
True if the emoji supports Fitzpatrick scale skin tone modifiers.
Constructor Details
#initialize(name) ⇒ Character
Returns a new instance of Character.
80 81 82 83 84 85 |
# File 'lib/emoji/character.rb', line 80 def initialize(name) @aliases = Array(name) @unicode_aliases = [] @tags = [] @skin_tones = false end |
Instance Attribute Details
#aliases ⇒ Object (readonly)
A list of names uniquely referring to this emoji.
20 21 22 |
# File 'lib/emoji/character.rb', line 20 def aliases @aliases end |
#category ⇒ Object
The category for this emoji as per Apple’s character palette
23 24 25 |
# File 'lib/emoji/character.rb', line 23 def category @category end |
#description ⇒ Object
The Unicode description text
26 27 28 |
# File 'lib/emoji/character.rb', line 26 def description @description end |
#image_filename ⇒ Object
98 99 100 101 102 103 104 |
# File 'lib/emoji/character.rb', line 98 def image_filename if defined? @image_filename @image_filename else default_image_filename end end |
#ios_version ⇒ Object
The iOS version where this emoji first debuted
32 33 34 |
# File 'lib/emoji/character.rb', line 32 def ios_version @ios_version end |
#skin_tones=(value) ⇒ Object (writeonly)
Sets the attribute skin_tones
17 18 19 |
# File 'lib/emoji/character.rb', line 17 def skin_tones=(value) @skin_tones = value end |
#tags ⇒ Object (readonly)
A list of tags associated with an emoji. Multiple emojis can share the same tags.
74 75 76 |
# File 'lib/emoji/character.rb', line 74 def @tags end |
#unicode_aliases ⇒ Object (readonly)
A list of Unicode strings that uniquely refer to this emoji.
41 42 43 |
# File 'lib/emoji/character.rb', line 41 def unicode_aliases @unicode_aliases end |
#unicode_version ⇒ Object
The Unicode spec version where this emoji first debuted
29 30 31 |
# File 'lib/emoji/character.rb', line 29 def unicode_version @unicode_version end |
Class Method Details
.hex_inspect(str) ⇒ Object
Inspect individual Unicode characters in a string by dumping its codepoints in hexadecimal format.
7 8 9 |
# 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 |
Instance Method Details
#add_alias(name) ⇒ Object
36 37 38 |
# File 'lib/emoji/character.rb', line 36 def add_alias(name) aliases << name end |
#add_tag(tag) ⇒ Object
76 77 78 |
# File 'lib/emoji/character.rb', line 76 def add_tag(tag) << tag end |
#add_unicode_alias(str) ⇒ Object
68 69 70 |
# File 'lib/emoji/character.rb', line 68 def add_unicode_alias(str) unicode_aliases << str end |
#custom? ⇒ Boolean
True if the emoji is not a standard Emoji character.
12 |
# File 'lib/emoji/character.rb', line 12 def custom?() !raw end |
#hex_inspect ⇒ Object
92 93 94 |
# File 'lib/emoji/character.rb', line 92 def hex_inspect self.class.hex_inspect(raw) end |
#inspect ⇒ Object
87 88 89 90 |
# File 'lib/emoji/character.rb', line 87 def inspect hex = '(%s)' % hex_inspect unless custom? %(#<#{self.class.name}:#{name}#{hex}>) end |
#name ⇒ Object
34 |
# File 'lib/emoji/character.rb', line 34 def name() aliases.first end |
#raw ⇒ Object
Raw Unicode string for an emoji. Nil if emoji is non-standard.
44 |
# File 'lib/emoji/character.rb', line 44 def raw() unicode_aliases.first end |
#raw_skin_tone_variants ⇒ Object
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.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# 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 |
#skin_tones? ⇒ Boolean
True if the emoji supports Fitzpatrick scale skin tone modifiers
15 |
# File 'lib/emoji/character.rb', line 15 def skin_tones?() @skin_tones end |