Class: Discorb::UnicodeEmoji
Overview
Represents a unicode emoji (default emoji) in discord.
Instance Attribute Summary collapse
-
#name -> String
readonly
The name of the emoji.
-
#skin_tone -> Integer
readonly
The skin tone of the emoji.
-
#value -> String
readonly
The unicode value of the emoji.
Instance Method Summary collapse
-
#initialize(name, tone: 0) -> UnicodeEmoji
constructor
Initialize a new unicode emoji.
- #inspect -> Object
-
#to_s -> String
The unicode string of the emoji.
-
#to_uri -> String
Format the emoji for URI.
Methods inherited from Emoji
Constructor Details
#initialize(name, tone: 0) -> UnicodeEmoji
Initialize a new unicode emoji.
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 |
# File 'lib/discorb/emoji.rb', line 232 def initialize(name, tone: 0) if EmojiTable::DISCORD_TO_UNICODE.key?(name) @name = name @value = EmojiTable::DISCORD_TO_UNICODE[name] elsif EmojiTable::UNICODE_TO_DISCORD.key?(name) @name = EmojiTable::UNICODE_TO_DISCORD[name][0] @value = name elsif EmojiTable::SKIN_TONES.any? { |t| name.include?(t) } name2 = name.dup EmojiTable::SKIN_TONES.each.with_index do |t, i| next unless name2.include?(t) @skin_tone = i name2.sub!(t, "") break end raise ArgumentError, "Invalid skin tone: #{tone}" unless @skin_tone @name = EmojiTable::UNICODE_TO_DISCORD[name2].first @value = name else raise ArgumentError, "No such emoji: #{name}" end if tone.positive? unless @value = EmojiTable::DISCORD_TO_UNICODE["#{name}_tone#{tone}"] raise ArgumentError, "Invalid skin tone for emoji: #{name}" end @name = "#{name}_tone#{tone}" @skin_tone = tone end end |
Instance Attribute Details
#name -> String (readonly)
Returns The name of the emoji. (e.g. :grinning:).
220 221 222 |
# File 'lib/discorb/emoji.rb', line 220 def name @name end |
#skin_tone -> Integer (readonly)
Returns The skin tone of the emoji.
224 225 226 |
# File 'lib/discorb/emoji.rb', line 224 def skin_tone @skin_tone end |
#value -> String (readonly)
Returns The unicode value of the emoji. (e.g. U+1F600).
222 223 224 |
# File 'lib/discorb/emoji.rb', line 222 def value @value end |
Instance Method Details
#inspect -> Object
280 281 282 |
# File 'lib/discorb/emoji.rb', line 280 def inspect "#<#{self.class} :#{@name}:>" end |
#to_s -> String
Returns The unicode string of the emoji.
267 268 269 |
# File 'lib/discorb/emoji.rb', line 267 def to_s @value end |
#to_uri -> String
Format the emoji for URI.
276 277 278 |
# File 'lib/discorb/emoji.rb', line 276 def to_uri URI.encode_www_form_component(@value) end |