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.
-
#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.
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
- #image_filename ⇒ Object
-
#initialize(name) ⇒ Character
constructor
A new instance of Character.
- #inspect ⇒ Object
- #name ⇒ Object
-
#raw ⇒ Object
Raw Unicode string for an emoji.
Constructor Details
#initialize(name) ⇒ Character
Returns a new instance of Character.
39 40 41 42 43 |
# File 'lib/emoji/character.rb', line 39 def initialize(name) @aliases = Array(name) @unicode_aliases = [] @tags = [] end |
Instance Attribute Details
#aliases ⇒ Object (readonly)
A list of names uniquely referring to this emoji.
13 14 15 |
# File 'lib/emoji/character.rb', line 13 def aliases @aliases end |
#tags ⇒ Object (readonly)
A list of tags associated with an emoji. Multiple emojis can share the same tags.
33 34 35 |
# File 'lib/emoji/character.rb', line 33 def @tags end |
#unicode_aliases ⇒ Object (readonly)
A list of Unicode strings that uniquely refer to this emoji.
22 23 24 |
# File 'lib/emoji/character.rb', line 22 def unicode_aliases @unicode_aliases end |
Class Method Details
.hex_inspect(str) ⇒ Object
Inspect individual Unicode characters in a string by dumping its codepoints in hexadecimal format.
5 6 7 |
# File 'lib/emoji/character.rb', line 5 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
17 18 19 |
# File 'lib/emoji/character.rb', line 17 def add_alias(name) aliases << name end |
#add_tag(tag) ⇒ Object
35 36 37 |
# File 'lib/emoji/character.rb', line 35 def add_tag(tag) << tag end |
#add_unicode_alias(str) ⇒ Object
27 28 29 |
# File 'lib/emoji/character.rb', line 27 def add_unicode_alias(str) unicode_aliases << str end |
#custom? ⇒ Boolean
True if the emoji is not a standard Emoji character.
10 |
# File 'lib/emoji/character.rb', line 10 def custom?() !raw end |
#hex_inspect ⇒ Object
50 51 52 |
# File 'lib/emoji/character.rb', line 50 def hex_inspect self.class.hex_inspect(raw) end |
#image_filename ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/emoji/character.rb', line 54 def image_filename if custom? '%s.png' % name else 'unicode/%s.png' % hex_inspect end end |
#inspect ⇒ Object
45 46 47 48 |
# File 'lib/emoji/character.rb', line 45 def inspect hex = '(%s)' % hex_inspect unless custom? %(#<#{self.class.name}:#{name}#{hex}>) end |
#name ⇒ Object
15 |
# File 'lib/emoji/character.rb', line 15 def name() aliases.first end |
#raw ⇒ Object
Raw Unicode string for an emoji. Nil if emoji is non-standard.
25 |
# File 'lib/emoji/character.rb', line 25 def raw() unicode_aliases.first end |