Class: Emoji::Character

Inherits:
Object
  • Object
show all
Defined in:
lib/emoji/character.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#aliasesObject (readonly)

A list of names uniquely referring to this emoji.



13
14
15
# File 'lib/emoji/character.rb', line 13

def aliases
  @aliases
end

#tagsObject (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
  @tags
end

#unicode_aliasesObject (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)
  tags << 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.

Returns:

  • (Boolean)


10
# File 'lib/emoji/character.rb', line 10

def custom?() !raw end

#hex_inspectObject



50
51
52
# File 'lib/emoji/character.rb', line 50

def hex_inspect
  self.class.hex_inspect(raw)
end

#image_filenameObject



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

#inspectObject



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

#nameObject



15
# File 'lib/emoji/character.rb', line 15

def name() aliases.first end

#rawObject

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