Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Have `unicode_aliases` include emoji's raw representation as well

This brings it up to par with `aliases`, which includes `name` as well.
  • Loading branch information...
commit 01394ed1399389b346dae99f668b36aad653666e 1 parent 2530b24
@mislav mislav authored
Showing with 15 additions and 8 deletions.
  1. +1 −3 lib/emoji.rb
  2. +4 −5 lib/emoji/character.rb
  3. +10 −0 test/emoji_test.rb
View
4 lib/emoji.rb
@@ -94,9 +94,7 @@ def names_index
def unicodes_index
@unicodes_index ||= create_index do |mapping|
all.each do |emoji|
- unicodes = emoji.unicode_aliases.dup
- unicodes << emoji.raw unless emoji.custom?
- unicodes.each do |unicode|
+ emoji.unicode_aliases.each do |unicode|
mapping[unicode] = emoji
end
end
View
9 lib/emoji/character.rb
@@ -8,9 +8,6 @@ def self.hex_inspect(str)
str.codepoints.map { |c| c.to_s(16).rjust(4, '0') }.join('-')
end
- # Raw Unicode string for an emoji. Nil if emoji is non-standard.
- attr_reader :raw
-
# True if the emoji is not a standard Emoji character.
def custom?() !raw end
@@ -28,6 +25,9 @@ def add_alias(name)
# variation selector character.
attr_reader :unicode_aliases
+ # Raw Unicode string for an emoji. Nil if emoji is non-standard.
+ def raw() unicode_aliases.first end
+
def add_unicode_alias(str)
unicode_aliases << str
end
@@ -41,9 +41,8 @@ def add_tag(tag)
end
def initialize(raw)
- @raw = raw
@aliases = []
- @unicode_aliases = []
+ @unicode_aliases = Array(raw)
@tags = []
# Automatically add a representation of this emoji without the variation
View
10 test/emoji_test.rb
@@ -51,6 +51,16 @@ class EmojiTest < TestCase
assert_equal "not-\u{1234}-found", emoji
end
+ test "unicode_aliases" do
+ emoji = Emoji.find_by_unicode("\u{1f237}")
+ assert_equal ["\u{1f237}", "\u{6708}"], emoji.unicode_aliases
+ end
+
+ test "unicode_aliases includes form without variation selector" do
+ emoji = Emoji.find_by_alias("heart")
+ assert_equal ["\u{2764}\u{fe0f}", "\u{2764}"], emoji.unicode_aliases
+ end
+
test "emojis have tags" do
emoji = Emoji.find_by_alias('smile')
assert emoji.tags.include?('happy')
Please sign in to comment.
Something went wrong with that request. Please try again.