Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
rumoji
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ikcrm_common
rumoji
Commits
44821e6c
Commit
44821e6c
authored
Jan 29, 2013
by
Mark Wunsch
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle emoji in a more OO, and use sets for lookup
parent
7efaed20
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
424 additions
and
330 deletions
+424
-330
lib/rumoji.rb
+8
-326
lib/rumoji/emoji.rb
+343
-0
spec/rumoji/emoji_spec.rb
+70
-0
spec/rumoji_spec.rb
+3
-4
No files found.
lib/rumoji.rb
View file @
44821e6c
# -*- encoding: utf-8 -*-
# -*- encoding: utf-8 -*-
require
"rumoji/version"
require
"rumoji/version"
require
"rumoji/emoji"
require
'stringio'
require
'stringio'
module
Rumoji
module
Rumoji
...
@@ -7,38 +8,29 @@ module Rumoji
...
@@ -7,38 +8,29 @@ module Rumoji
def
encode
(
str
)
def
encode
(
str
)
remapped_codepoints
=
str
.
codepoints
.
flat_map
do
|
codepoint
|
remapped_codepoints
=
str
.
codepoints
.
flat_map
do
|
codepoint
|
emoji
=
E
MOJI_NAME_TO_CODEPOINT
.
key
codepoint_as_hex
(
codepoint
)
emoji
=
E
moji
.
find_by_codepoint
(
codepoint
)
emoji
?
":
#{
emoji
}
:"
.
codepoints
.
entries
:
codepoint
emoji
?
":
#{
emoji
.
code
}
:"
.
codepoints
.
entries
:
codepoint
end
end
remapped_codepoints
.
pack
(
"U*"
)
remapped_codepoints
.
pack
(
"U*"
)
end
end
def
decode
(
str
)
def
decode
(
str
)
duplicate
=
str
.
dup
str
.
gsub
(
/:(\w+):/
)
{
|
sym
|
Emoji
.
find
(
$1
.
intern
).
to_s
}
EMOJI_NAME_TO_CODEPOINT
.
each_pair
do
|
key
,
value
|
duplicate
.
gsub!
":
#{
key
}
:"
,
[
value
.
to_i
(
16
)].
pack
(
"U"
)
end
duplicate
end
end
def
encode_io
(
readable
,
writeable
=
StringIO
.
new
(
""
))
def
encode_io
(
readable
,
writeable
=
StringIO
.
new
(
""
))
readable
.
each_codepoint
do
|
codepoint
|
readable
.
each_codepoint
do
|
codepoint
|
emoji
=
codepoint_as_hex
(
codepoint
)
emoji
=
Emoji
.
find_by_codepoint
(
codepoint
)
emoji_or_character
=
EMOJI_NAME_TO_CODEPOINT
.
has_value?
(
emoji
)
?
":
#{
EMOJI_NAME_TO_CODEPOINT
.
key
(
emoji
)
}
:"
:
[
codepoint
].
pack
(
"U"
)
emoji_or_character
=
emoji
?
":
#{
emoji
.
code
}
:"
:
[
codepoint
].
pack
(
"U"
)
writeable
.
write
emoji_or_character
writeable
.
write
emoji_or_character
end
end
writeable
.
rewind
writeable
writeable
end
end
def
decode_io
(
readable
,
writeable
=
StringIO
.
new
(
""
))
def
decode_io
(
readable
,
writeable
=
StringIO
.
new
(
""
))
readable
.
each
do
|
word
|
readable
.
each_line
do
|
line
|
EMOJI_NAME_TO_CODEPOINT
.
each_pair
do
|
key
,
value
|
writeable
.
write
line
.
gsub
(
/:(\w+):/
)
{
|
sym
|
Emoji
.
find
(
$1
.
intern
).
to_s
}
word
.
gsub!
(
":
#{
key
}
:"
,
[
value
.
to_i
(
16
)].
pack
(
"U"
))
end
writeable
.
write
(
word
)
end
end
writeable
.
rewind
writeable
writeable
end
end
...
@@ -46,314 +38,4 @@ module Rumoji
...
@@ -46,314 +38,4 @@ module Rumoji
codepoint
.
to_s
(
16
).
upcase
codepoint
.
to_s
(
16
).
upcase
end
end
EMOJI_NAME_TO_CODEPOINT
=
{
# PEOPLE
smile:
"1F604"
,
laughing:
"1F606"
,
blush:
"1F60A"
,
smiley:
"1F603"
,
relaxed:
"263A"
,
smirk:
"1F60F"
,
heart_eyes:
"1F60D"
,
kissing_heart:
"1F618"
,
kissing_closed_eyes:
"1F61A"
,
flushed:
"1F633"
,
relieved:
"1F625"
,
satisfied:
"1F60C"
,
grin:
"1F601"
,
wink:
"1F609"
,
wink2:
"1F61C"
,
stuck_out_tongue_winking_eye:
"1F61C"
,
stuck_out_tongue_closed_eyes:
"1F61D"
,
grinning:
"1F600"
,
kissing:
"1F617"
,
kissing_smiling_eyes:
"1F619"
,
stuck_out_tongue:
"1F61B"
,
sleeping:
"1F634"
,
worried:
"1F61F"
,
frowning:
"1F626"
,
anguished:
"1F627"
,
open_mouth:
"1F62E"
,
grimacing:
"1F62C"
,
confused:
"1F615"
,
hushed:
"1F62F"
,
expressionless:
"1F611"
,
unamused:
"1F612"
,
sweat_smile:
"1F605"
,
sweat:
"1F613"
,
weary:
"1F629"
,
pensive:
"1F614"
,
dissapointed:
"1F61E"
,
confounded:
"1F616"
,
fearful:
"1F628"
,
cold_sweat:
"1F630"
,
persevere:
"1F623"
,
cry:
"1F622"
,
sob:
"1F62D"
,
joy:
"1F602"
,
astonished:
"1F632"
,
scream:
"1F631"
,
tired_face:
"1F62B"
,
angry:
"1F620"
,
rage:
"1F621"
,
triumph:
"1F624"
,
sleepy:
"1F62A"
,
yum:
"1F60B"
,
mask:
"1F637"
,
sunglasses:
"1F60E"
,
dizzy_face:
"1F635"
,
imp:
"1F47F"
,
smiling_imp:
"1F608"
,
neutral_face:
"1F610"
,
no_mouth:
"1F636"
,
innocent:
"1F607"
,
alien:
"1F47D"
,
yellow_heart:
"1F49B"
,
blue_heart:
"1F499"
,
purple_heart:
"1F49C"
,
heart:
"2764"
,
green_heart:
"1F49A"
,
broken_heart:
"1F494"
,
heartbeat:
"1F493"
,
heartpulse:
"1F497"
,
two_hearts:
"1F495"
,
revolving_hearts:
"1F49E"
,
cupid:
"1F498"
,
sparkling_heart:
"1F496"
,
sparkles:
"2728"
,
star:
"2B50"
,
# In "Nature" range
star2:
"1F31F"
,
dizzy:
"1F4AB"
,
boom:
"1F4A5"
,
collision:
"1F4A5"
,
anger:
"1F4A2"
,
# In "Symbols" range
exclamation:
"2757"
,
question:
"2753"
,
grey_exclamation:
"2755"
,
grey_question:
"2754"
,
zzz:
"1F4A4"
,
dash:
"1F4A8"
,
sweat_drops:
"1F4A6"
,
# In "Objects" range
notes:
"1F3B6"
,
musical_note:
"1F3B5"
,
fire:
"1F525"
,
# So much poop
hankey:
"1F4A9"
,
poop:
"1F4A9"
,
shit:
"1F4A9"
,
thumbsup:
"1F44D"
,
thumbsdown:
"1F44E"
,
ok_hand:
"1F44C"
,
punch:
"1F44A"
,
facepunch:
"1F44A"
,
fist:
"270A"
,
v:
"270C"
,
wave:
"1F44B"
,
hand:
"270B"
,
open_hands:
"1F450"
,
point_up:
"261D"
,
point_down:
"1F447"
,
point_left:
"1F448"
,
point_right:
"1F449"
,
raised_hands:
"1F64C"
,
pray:
"1F64F"
,
point_up_2:
"1F446"
,
clap:
"1F44F"
,
muscle:
"1F4AA"
,
walking:
"1F6B6"
,
runner:
"1F3C3"
,
running:
"1F3C3"
,
couple:
"1F46B"
,
family:
"1F46A"
,
two_men_holding_hands:
"1F46C"
,
two_women_holding_hands:
"1F46C"
,
dancer:
"1F483"
,
dancers:
"1F46F"
,
ok_woman:
"1F646"
,
no_good:
"1F645"
,
information_desk_person:
"1F481"
,
raised_hand:
"1F64B"
,
bride_with_veil:
"1F470"
,
person_with_pouting_face:
"1F64E"
,
person_frowning:
"1F64D"
,
bow:
"1F647"
,
couplekiss:
"1F48F"
,
couple_with_heart:
"1F491"
,
massage:
"1F486"
,
haircut:
"1F487"
,
nail_care:
"1F485"
,
boy:
"1F466"
,
girl:
"1F467"
,
woman:
"1F469"
,
man:
"1F468"
,
baby:
"1F476"
,
older_woman:
"1F475"
,
older_man:
"1F474"
,
person_with_blond_hair:
"1F471"
,
man_with_gua_pi_mao:
"1F472"
,
man_with_turban:
"1F473"
,
construction_worker:
"1F477"
,
cop:
"1F46E"
,
angel:
"1F47C"
,
princess:
"1F478"
,
# Cats
smiley_cat:
"1F63A"
,
smile_cat:
"1F638"
,
heart_eyes_cat:
"1F63B"
,
kissing_cat:
"1F63D"
,
smirk_cat:
"1F63C"
,
scream_cat:
"1F640"
,
crying_cat_face:
"1F63F"
,
joy_cat:
"1F639"
,
pouting_cat:
"1F63E"
,
japanese_ogre:
"1F479"
,
japanese_goblin:
"1F47A"
,
# Monkeys
see_no_evil:
"1F648"
,
hear_no_evil:
"1F649"
,
speak_no_evil:
"1F649"
,
guardsman:
"1F482"
,
skull:
"1F480"
,
feet:
"1F463"
,
lips:
"1F444"
,
kiss:
"1F48B"
,
droplet:
"1F4A7"
,
ear:
"1F442"
,
eyes:
"1F440"
,
nose:
"1F443"
,
tongue:
"1F445"
,
love_letter:
"1F48C"
,
bust_in_silhouette:
"1F464"
,
busts_in_silhouette:
"1F465"
,
speech_balloon:
"1F4AC"
,
thought_balloon:
"1F4AD"
,
# NATURE
sunny:
"2600"
,
umbrella:
"2614"
,
cloud:
"2601"
,
snowflake:
"2744"
,
snowman:
"26C4"
,
zap:
"26A1"
,
cyclone:
"1F300"
,
foggy:
"1F301"
,
ocean:
"1F30A"
,
# Animals
cat:
"1F431"
,
dog:
"1F436"
,
mouse:
"1F42D"
,
hamster:
"1F439"
,
rabbit:
"1F430"
,
wolf:
"1F43A"
,
frog:
"1F438"
,
tiger:
"1F42F"
,
koala:
"1F428"
,
bear:
"1F43B"
,
pig:
"1F437"
,
pig_nose:
"1F43D"
,
cow:
"1F42E"
,
boar:
"1F417"
,
monkey_face:
"1F435"
,
monkey:
"1F412"
,
horse:
"1F434"
,
racehorse:
"1F40E"
,
camel:
"1F42B"
,
sheep:
"1F411"
,
elephant:
"1F418"
,
panda_face:
"1F43C"
,
snake:
"1F40D"
,
bird:
"1F426"
,
baby_chick:
"1F424"
,
hatched_chick:
"1F425"
,
hatching_chick:
"1F423"
,
chicken:
"1F414"
,
penguin:
"1F427"
,
turtle:
"1F422"
,
bug:
"1F41B"
,
honeybee:
"1F41D"
,
ant:
"1F41C"
,
beetle:
"1F41E"
,
snail:
"1F40C"
,
octopus:
"1F419"
,
tropical_fish:
"1F420"
,
fish:
"1F41F"
,
whale:
"1F433"
,
whale2:
"1F40B"
,
dolphin:
"1F42C"
,
cow2:
"1F404"
,
ram:
"1F40F"
,
rat:
"1F400"
,
water_buffalo:
"1F403"
,
tiger2:
"1F405"
,
rabbit2:
"1F407"
,
dragon:
"1F409"
,
goat:
"1F410"
,
rooster:
"1F413"
,
dog2:
"1F415"
,
pig2:
"1F416"
,
mouse2:
"1F401"
,
ox:
"1F402"
,
dragon_face:
"1F432"
,
blowfish:
"1F421"
,
crocodile:
"1F40A"
,
dromedary_camel:
"1F42A"
,
leopard:
"1F406"
,
cat2:
"1F408"
,
poodle:
"1F429"
,
paw_prints:
"1F43E"
,
# Flowers
bouquet:
"1F490"
,
cherry_blossom:
"1F338"
,
tulip:
"1F337"
,
four_leaf_clover:
"1F340"
,
rose:
"1F339"
,
sunflower:
"1F33B"
,
hibiscus:
"1F33A"
,
maple_leaf:
"1F341"
,
leaves:
"1F343"
,
fallen_leaf:
"1F342"
,
herb:
"1F33F"
,
mushroom:
"1F344"
,
cactus:
"1F335"
,
palm_tree:
"1F334"
,
evergreen_tree:
"1F332"
,
deciduous_tree:
"1F333"
,
chestnut:
"1F330"
,
seedling:
"1F331"
,
blossum:
"1F33C"
,
ear_of_rice:
"1F33E"
,
shell:
"1F41A"
,
globe_with_meridians:
"1F310"
,
# Moon
sun_with_face:
"1F31E"
,
full_moon_with_face:
"1F31D"
,
new_moon_with_face:
"1F31A"
,
new_moon:
"1F311"
,
waxing_crescent_moon:
"1F312"
,
first_quarter_moon:
"1F313"
,
waxing_gibbous_moon:
"1F314"
,
full_moon:
"1F315"
,
waning_gibbous_moon:
"1F316"
,
last_quarter_moon:
"1F317"
,
waning_crescent_moon:
"1F318"
,
last_quarter_moon_with_face:
"1F31C"
,
first_quarter_moon_with_face:
"1F31B"
,
moon:
"1F319"
,
earth_africa:
"1F30D"
,
earth_americas:
"1F30E"
,
earth_asia:
"1F30F"
,
volcano:
"1F30B"
,
milky_way:
"1F30C"
,
partly_sunny:
"26C5"
}
end
end
lib/rumoji/emoji.rb
0 → 100644
View file @
44821e6c
# -*- encoding: utf-8 -*-
module
Rumoji
class
Emoji
require
'set'
attr_reader
:name
def
initialize
(
string
,
symbols
,
name
)
@codepoints
=
string
.
codepoints
@cheat_codes
=
[
symbols
].
flatten
@name
=
name
end
def
code
@cheat_codes
.
first
end
def
include?
(
symbol
)
@cheat_codes
.
include?
symbol
.
to_sym
end
def
to_s
@codepoints
.
to_a
.
pack
(
"U*"
)
end
def
hash
code
.
hash
end
def
hex
@codepoints
.
map
{
|
point
|
point
.
to_s
(
16
).
upcase
}.
join
end
PEOPLE
=
Set
[
self
.
new
(
"
\u
{1F604}"
,
[
:smile
],
"SMILING FACE WITH OPEN MOUTH AND SMILING EYES"
),
self
.
new
(
"
\u
{1F606}"
,
[
:laughing
],
""
),
self
.
new
(
"
\u
{1F60A}"
,
[
:blush
],
""
),
self
.
new
(
"
\u
{1F603}"
,
[
:smiley
],
""
),
self
.
new
(
"
\u
{263A}"
,
[
:relaxed
],
""
),
self
.
new
(
"
\u
{1F60F}"
,
[
:smirk
],
""
),
self
.
new
(
"
\u
{1F60D}"
,
[
:heart_eyes
],
""
),
self
.
new
(
"
\u
{1F618}"
,
[
:kissing_heart
],
""
),
self
.
new
(
"
\u
{1F61A}"
,
[
:kissing_closed_eyes
],
""
),
self
.
new
(
"
\u
{1F633}"
,
[
:flushed
],
""
),
self
.
new
(
"
\u
{1F625}"
,
[
:relieved
],
""
),
self
.
new
(
"
\u
{1F60C}"
,
[
:satisfied
],
""
),
self
.
new
(
"
\u
{1F601}"
,
[
:grin
],
""
),
self
.
new
(
"
\u
{1F609}"
,
[
:wink
],
""
),
self
.
new
(
"
\u
{1F61C}"
,
[
:wink2
,
:stuck_out_tongue_winking_eye
],
""
),
self
.
new
(
"
\u
{1F61D}"
,
[
:stuck_out_tongue_closed_eyes
],
""
),
self
.
new
(
"
\u
{1F600}"
,
[
:grinning
],
""
),
self
.
new
(
"
\u
{1F617}"
,
[
:kissing
],
""
),
self
.
new
(
"
\u
{1F619}"
,
[
:kissing_smiling_eyes
],
""
),
self
.
new
(
"
\u
{1F61B}"
,
[
:stuck_out_tongue
],
""
),
self
.
new
(
"
\u
{1F634}"
,
[
:sleeping
],
""
),
self
.
new
(
"
\u
{1F61F}"
,
[
:worried
],
""
),
self
.
new
(
"
\u
{1F626}"
,
[
:frowning
],
""
),
self
.
new
(
"
\u
{1F627}"
,
[
:anguished
],
""
),
self
.
new
(
"
\u
{1F62E}"
,
[
:open_mouth
],
""
),
self
.
new
(
"
\u
{1F62C}"
,
[
:grimacing
],
""
),
self
.
new
(
"
\u
{1F615}"
,
[
:confused
],
""
),
self
.
new
(
"
\u
{1F62F}"
,
[
:hushed
],
""
),
self
.
new
(
"
\u
{1F611}"
,
[
:expressionless
],
""
),
self
.
new
(
"
\u
{1F612}"
,
[
:unamused
],
""
),
self
.
new
(
"
\u
{1F605}"
,
[
:sweat_smile
],
""
),
self
.
new
(
"
\u
{1F613}"
,
[
:sweat
],
""
),
self
.
new
(
"
\u
{1F629}"
,
[
:weary
],
""
),
self
.
new
(
"
\u
{1F614}"
,
[
:pensive
],
""
),
self
.
new
(
"
\u
{1F61E}"
,
[
:dissapointed
],
""
),
self
.
new
(
"
\u
{1F616}"
,
[
:confounded
],
""
),
self
.
new
(
"
\u
{1F628}"
,
[
:fearful
],
""
),
self
.
new
(
"
\u
{1F630}"
,
[
:cold_sweat
],
""
),
self
.
new
(
"
\u
{1F623}"
,
[
:persevere
],
""
),
self
.
new
(
"
\u
{1F622}"
,
[
:cry
],
""
),
self
.
new
(
"
\u
{1F62D}"
,
[
:sob
],
""
),
self
.
new
(
"
\u
{1F602}"
,
[
:joy
],
""
),
self
.
new
(
"
\u
{1F632}"
,
[
:astonished
],
""
),
self
.
new
(
"
\u
{1F631}"
,
[
:scream
],
""
),
self
.
new
(
"
\u
{1F62B}"
,
[
:tired_face
],
""
),
self
.
new
(
"
\u
{1F620}"
,
[
:angry
],
""
),
self
.
new
(
"
\u
{1F621}"
,
[
:rage
],
""
),
self
.
new
(
"
\u
{1F624}"
,
[
:triumph
],
""
),
self
.
new
(
"
\u
{1F62A}"
,
[
:sleepy
],
""
),
self
.
new
(
"
\u
{1F60B}"
,
[
:yum
],
""
),
self
.
new
(
"
\u
{1F637}"
,
[
:mask
],
""
),
self
.
new
(
"
\u
{1F60E}"
,
[
:sunglasses
],
""
),
self
.
new
(
"
\u
{1F635}"
,
[
:dizzy_face
],
""
),
self
.
new
(
"
\u
{1F47F}"
,
[
:imp
],
""
),
self
.
new
(
"
\u
{1F608}"
,
[
:smiling_imp
],
""
),
self
.
new
(
"
\u
{1F610}"
,
[
:neutral_face
],
""
),
self
.
new
(
"
\u
{1F636}"
,
[
:no_mouth
],
""
),
self
.
new
(
"
\u
{1F607}"
,
[
:innocent
],
""
),
self
.
new
(
"
\u
{1F47D}"
,
[
:alien
],
""
),
self
.
new
(
"
\u
{1F49B}"
,
[
:yellow_heart
],
""
),
self
.
new
(
"
\u
{1F499}"
,
[
:blue_heart
],
""
),
self
.
new
(
"
\u
{1F49C}"
,
[
:purple_heart
],
""
),
self
.
new
(
"
\u
{2764}"
,
[
:heart
],
""
),
self
.
new
(
"
\u
{1F49A}"
,
[
:green_heart
],
""
),
self
.
new
(
"
\u
{1F494}"
,
[
:broken_heart
],
""
),
self
.
new
(
"
\u
{1F493}"
,
[
:heartbeat
],
""
),
self
.
new
(
"
\u
{1F497}"
,
[
:heartpulse
],
""
),
self
.
new
(
"
\u
{1F495}"
,
[
:two_hearts
],
""
),
self
.
new
(
"
\u
{1F49E}"
,
[
:revolving_hearts
],
""
),
self
.
new
(
"
\u
{1F498}"
,
[
:cupid
],
""
),
self
.
new
(
"
\u
{1F496}"
,
[
:sparkling_heart
],
""
),
self
.
new
(
"
\u
{2728}"
,
[
:sparkles
],
""
),
self
.
new
(
"
\u
{2B50}"
,
[
:star
],
""
),
self
.
new
(
"
\u
{1F31F}"
,
[
:star2
],
""
),
self
.
new
(
"
\u
{1F4AB}"
,
[
:dizzy
],
""
),
self
.
new
(
"
\u
{1F4A5}"
,
[
:boom
,
:collision
],
""
),
self
.
new
(
"
\u
{1F4A2}"
,
[
:anger
],
""
),
self
.
new
(
"
\u
{2757}"
,
[
:exclamation
],
""
),
self
.
new
(
"
\u
{2753}"
,
[
:question
],
""
),
self
.
new
(
"
\u
{2755}"
,
[
:grey_exclamation
],
""
),
self
.
new
(
"
\u
{2754}"
,
[
:grey_question
],
""
),
self
.
new
(
"
\u
{1F4A4}"
,
[
:zzz
],
""
),
self
.
new
(
"
\u
{1F4A8}"
,
[
:dash
],
""
),
self
.
new
(
"
\u
{1F4A6}"
,
[
:sweat_drops
],
""
),
self
.
new
(
"
\u
{1F3B6}"
,
[
:notes
],
""
),
self
.
new
(
"
\u
{1F3B5}"
,
[
:musical_note
],
""
),
self
.
new
(
"
\u
{1F525}"
,
[
:fire
],
""
),
# Poop
self
.
new
(
"
\u
{1F4A9}"
,
[
:hankey
,
:poop
,
:shit
],
"PILE OF POO"
),
self
.
new
(
"
\u
{1F44D}"
,
[
:thumbsup
],
""
),
self
.
new
(
"
\u
{1F44E}"
,
[
:thumbsdown
],
""
),
self
.
new
(
"
\u
{1F44C}"
,
[
:ok_hand
],
""
),
self
.
new
(
"
\u
{1F44A}"
,
[
:punch
,
:facepunch
],
""
),
self
.
new
(
"
\u
{270A}"
,
[
:fist
],
""
),
self
.
new
(
"
\u
{270C}"
,
[
:v
],
""
),
self
.
new
(
"
\u
{1F44B}"
,
[
:wave
],
""
),
self
.
new
(
"
\u
{270B}"
,
[
:hand
],
""
),
self
.
new
(
"
\u
{1F450}"
,
[
:open_hands
],
""
),
self
.
new
(
"
\u
{261D}"
,
[
:point_up
],
""
),
self
.
new
(
"
\u
{1F447}"
,
[
:point_down
],
""
),
self
.
new
(
"
\u
{1F448}"
,
[
:point_left
],
""
),
self
.
new
(
"
\u
{1F449}"
,
[
:point_right
],
""
),
self
.
new
(
"
\u
{1F64C}"
,
[
:raised_hands
],
""
),
self
.
new
(
"
\u
{1F64F}"
,
[
:pray
],
""
),
self
.
new
(
"
\u
{1F446}"
,
[
:point_up_2
],
""
),
self
.
new
(
"
\u
{1F44F}"
,
[
:clap
],
""
),
self
.
new
(
"
\u
{1F4AA}"
,
[
:muscle
],
""
),
self
.
new
(
"
\u
{1F6B6}"
,
[
:walking
],
""
),
self
.
new
(
"
\u
{1F3C3}"
,
[
:runner
,
:running
],
"RUNNER"
),
self
.
new
(
"
\u
{1F46B}"
,
[
:couple
],
"MAN AND WOMAN HOLDING HANDS"
),
self
.
new
(
"
\u
{1F46A}"
,
[
:family
],
"FAMILY"
),
self
.
new
(
"
\u
{1F46C}"
,
[
:two_men_holding_hands
],
"TWO MEN HOLDING HANDS"
),
self
.
new
(
"
\u
{1F46D}"
,
[
:two_women_holding_hands
],
"TWO WOMEN HOLDING HANDS"
),
self
.
new
(
"
\u
{1F483}"
,
[
:dancer
],
""
),
self
.
new
(
"
\u
{1F46F}"
,
[
:dancers
],
""
),
self
.
new
(
"
\u
{1F646}"
,
[
:ok_woman
],
""
),
self
.
new
(
"
\u
{1F645}"
,
[
:no_good
],
""
),
self
.
new
(
"
\u
{1F481}"
,
[
:information_desk_person
],
""
),
self
.
new
(
"
\u
{1F64B}"
,
[
:raised_hand
],
""
),
self
.
new
(
"
\u
{1F470}"
,
[
:bride_with_veil
],
""
),
self
.
new
(
"
\u
{1F64E}"
,
[
:person_with_pouting_face
],
""
),
self
.
new
(
"
\u
{1F64D}"
,
[
:person_frowning
],
""
),
self
.
new
(
"
\u
{1F647}"
,
[
:bow
],
""
),
self
.
new
(
"
\u
{1F48F}"
,
[
:couplekiss
],
""
),
self
.
new
(
"
\u
{1F491}"
,
[
:couple_with_heart
],
""
),
self
.
new
(
"
\u
{1F486}"
,
[
:massage
],
""
),
self
.
new
(
"
\u
{1F487}"
,
[
:haircut
],
""
),
self
.
new
(
"
\u
{1F485}"
,
[
:nail_care
],
""
),
self
.
new
(
"
\u
{1F466}"
,
[
:boy
],
""
),
self
.
new
(
"
\u
{1F467}"
,
[
:girl
],
""
),
self
.
new
(
"
\u
{1F469}"
,
[
:woman
],
""
),
self
.
new
(
"
\u
{1F468}"
,
[
:man
],
""
),
self
.
new
(
"
\u
{1F476}"
,
[
:baby
],
""
),
self
.
new
(
"
\u
{1F475}"
,
[
:older_woman
],
""
),
self
.
new
(
"
\u
{1F474}"
,
[
:older_man
],
""
),
self
.
new
(
"
\u
{1F471}"
,
[
:person_with_blond_hair
],
""
),
self
.
new
(
"
\u
{1F472}"
,
[
:man_with_gua_pi_mao
],
""
),
self
.
new
(
"
\u
{1F473}"
,
[
:man_with_turban
],
""
),
self
.
new
(
"
\u
{1F477}"
,
[
:construction_worker
],
""
),
self
.
new
(
"
\u
{1F46E}"
,
[
:cop
],
""
),
self
.
new
(
"
\u
{1F47C}"
,
[
:angel
],
""
),
self
.
new
(
"
\u
{1F478}"
,
[
:princess
],
""
),
# Cats
self
.
new
(
"
\u
{1F63A}"
,
[
:smiley_cat
],
""
),
self
.
new
(
"
\u
{1F638}"
,
[
:smile_cat
],
""
),
self
.
new
(
"
\u
{1F63B}"
,
[
:heart_eyes_cat
],
""
),
self
.
new
(
"
\u
{1F63D}"
,
[
:kissing_cat
],
""
),
self
.
new
(
"
\u
{1F63C}"
,
[
:smirk_cat
],
""
),
self
.
new
(
"
\u
{1F640}"
,
[
:scream_cat
],
""
),
self
.
new
(
"
\u
{1F63F}"
,
[
:crying_cat_face
],
""
),
self
.
new
(
"
\u
{1F639}"
,
[
:joy_cat
],
""
),
self
.
new
(
"
\u
{1F63E}"
,
[
:pouting_cat
],
""
),
self
.
new
(
"
\u
{1F479}"
,
[
:japanese_ogre
],
""
),
self
.
new
(
"
\u
{1F47A}"
,
[
:japanese_goblin
],
""
),
# Monkeys
self
.
new
(
"
\u
{1F648}"
,
[
:see_no_evil
],
""
),
self
.
new
(
"
\u
{1F649}"
,
[
:hear_no_evil
,
:speak_no_evil
],
""
),
self
.
new
(
"
\u
{1F482}"
,
[
:guardsman
],
""
),
self
.
new
(
"
\u
{1F480}"
,
[
:skull
],
""
),
self
.
new
(
"
\u
{1F463}"
,
[
:feet
],
""
),
self
.
new
(
"
\u
{1F444}"
,
[
:lips
],
""
),
self
.
new
(
"
\u
{1F48B}"
,
[
:kiss
],
""
),
self
.
new
(
"
\u
{1F4A7}"
,
[
:droplet
],
""
),
self
.
new
(
"
\u
{1F442}"
,
[
:ear
],
""
),
self
.
new
(
"
\u
{1F440}"
,
[
:eyes
],
""
),
self
.
new
(
"
\u
{1F443}"
,
[
:nose
],
""
),
self
.
new
(
"
\u
{1F445}"
,
[
:tongue
],
""
),
self
.
new
(
"
\u
{1F48C}"
,
[
:love_letter
],
""
),
self
.
new
(
"
\u
{1F464}"
,
[
:bust_in_silhouette
],
""
),
self
.
new
(
"
\u
{1F465}"
,
[
:busts_in_silhouette
],
""
),
self
.
new
(
"
\u
{1F4AC}"
,
[
:speech_balloon
],
""
),
self
.
new
(
"
\u
{1F4AD}"
,
[
:thought_balloon
],
""
),
]
NATURE
=
Set
[
self
.
new
(
"
\u
{2600}"
,
[
:sunny
],
""
),
self
.
new
(
"
\u
{2614}"
,
[
:umbrella
],
""
),
self
.
new
(
"
\u
{2601}"
,
[
:cloud
],
""
),
self
.
new
(
"
\u
{2744}"
,
[
:snowflake
],
""
),
self
.
new
(
"
\u
{26C4}"
,
[
:snowman
],
""
),
self
.
new
(
"
\u
{26A1}"
,
[
:zap
],
""
),
self
.
new
(
"
\u
{1F300}"
,
[
:cyclone
],
""
),
self
.
new
(
"
\u
{1F301}"
,
[
:foggy
],
""
),
self
.
new
(
"
\u
{1F30A}"
,
[
:ocean
],
""
),
# Animals
self
.
new
(
"
\u
{1F431}"
,
[
:cat
],
""
),
self
.
new
(
"
\u
{1F436}"
,
[
:dog
],
""
),
self
.
new
(
"
\u
{1F42D}"
,
[
:mouse
],
""
),
self
.
new
(
"
\u
{1F439}"
,
[
:hamster
],
""
),
self
.
new
(
"
\u
{1F430}"
,
[
:rabbit
],
""
),
self
.
new
(
"
\u
{1F43A}"
,
[
:wolf
],
""
),
self
.
new
(
"
\u
{1F438}"
,
[
:frog
],
""
),
self
.
new
(
"
\u
{1F42F}"
,
[
:tiger
],
""
),
self
.
new
(
"
\u
{1F428}"
,
[
:koala
],
""
),
self
.
new
(
"
\u
{1F43B}"
,
[
:bear
],
""
),
self
.
new
(
"
\u
{1F437}"
,
[
:pig
],
""
),
self
.
new
(
"
\u
{1F43D}"
,
[
:pig_nose
],
""
),
self
.
new
(
"
\u
{1F42E}"
,
[
:cow
],
""
),
self
.
new
(
"
\u
{1F417}"
,
[
:boar
],
""
),
self
.
new
(
"
\u
{1F435}"
,
[
:monkey_face
],
""
),
self
.
new
(
"
\u
{1F412}"
,
[
:monkey
],
""
),
self
.
new
(
"
\u
{1F434}"
,
[
:horse
],
""
),
self
.
new
(
"
\u
{1F40E}"
,
[
:racehorse
],
""
),
self
.
new
(
"
\u
{1F42B}"
,
[
:camel
],
""
),
self
.
new
(
"
\u
{1F411}"
,
[
:sheep
],
""
),
self
.
new
(
"
\u
{1F418}"
,
[
:elephant
],
""
),
self
.
new
(
"
\u
{1F43C}"
,
[
:panda_face
],
""
),
self
.
new
(
"
\u
{1F40D}"
,
[
:snake
],
""
),
self
.
new
(
"
\u
{1F426}"
,
[
:bird
],
""
),
self
.
new
(
"
\u
{1F424}"
,
[
:baby_chick
],
""
),
self
.
new
(
"
\u
{1F425}"
,
[
:hatched_chick
],
""
),
self
.
new
(
"
\u
{1F423}"
,
[
:hatching_chick
],
""
),
self
.
new
(
"
\u
{1F414}"
,
[
:chicken
],
""
),
self
.
new
(
"
\u
{1F427}"
,
[
:penguin
],
""
),
self
.
new
(
"
\u
{1F422}"
,
[
:turtle
],
""
),
self
.
new
(
"
\u
{1F41B}"
,
[
:bug
],
""
),
self
.
new
(
"
\u
{1F41D}"
,
[
:honeybee
],
""
),
self
.
new
(
"
\u
{1F41C}"
,
[
:ant
],
""
),
self
.
new
(
"
\u
{1F41E}"
,
[
:beetle
],
""
),
self
.
new
(
"
\u
{1F40C}"
,
[
:snail
],
""
),
self
.
new
(
"
\u
{1F419}"
,
[
:octopus
],
""
),
self
.
new
(
"
\u
{1F420}"
,
[
:tropical_fish
],
""
),
self
.
new
(
"
\u
{1F41F}"
,
[
:fish
],
""
),
self
.
new
(
"
\u
{1F433}"
,
[
:whale
],
""
),
self
.
new
(
"
\u
{1F40B}"
,
[
:whale2
],
""
),
self
.
new
(
"
\u
{1F42C}"
,
[
:dolphin
],
""
),
self
.
new
(
"
\u
{1F404}"
,
[
:cow2
],
""
),
self
.
new
(
"
\u
{1F40F}"
,
[
:ram
],
""
),
self
.
new
(
"
\u
{1F400}"
,
[
:rat
],
""
),
self
.
new
(
"
\u
{1F403}"
,
[
:water_buffalo
],
""
),
self
.
new
(
"
\u
{1F405}"
,
[
:tiger2
],
""
),
self
.
new
(
"
\u
{1F407}"
,
[
:rabbit2
],
""
),
self
.
new
(
"
\u
{1F409}"
,
[
:dragon
],
""
),
self
.
new
(
"
\u
{1F410}"
,
[
:goat
],
""
),
self
.
new
(
"
\u
{1F413}"
,
[
:rooster
],
""
),
self
.
new
(
"
\u
{1F415}"
,
[
:dog2
],
""
),
self
.
new
(
"
\u
{1F416}"
,
[
:pig2
],
""
),
self
.
new
(
"
\u
{1F401}"
,
[
:mouse2
],
""
),
self
.
new
(
"
\u
{1F402}"
,
[
:ox
],
""
),
self
.
new
(
"
\u
{1F432}"
,
[
:dragon_face
],
""
),
self
.
new
(
"
\u
{1F421}"
,
[
:blowfish
],
""
),
self
.
new
(
"
\u
{1F40A}"
,
[
:crocodile
],
""
),
self
.
new
(
"
\u
{1F42A}"
,
[
:dromedary_camel
],
""
),
self
.
new
(
"
\u
{1F406}"
,
[
:leopard
],
""
),
self
.
new
(
"
\u
{1F408}"
,
[
:cat2
],
""
),
self
.
new
(
"
\u
{1F429}"
,
[
:poodle
],
""
),
self
.
new
(
"
\u
{1F43E}"
,
[
:paw_prints
],
""
),
# Flowers
self
.
new
(
"
\u
{1F490}"
,
[
:bouquet
],
""
),
self
.
new
(
"
\u
{1F338}"
,
[
:cherry_blossom
],
""
),
self
.
new
(
"
\u
{1F337}"
,
[
:tulip
],
""
),
self
.
new
(
"
\u
{1F340}"
,
[
:four_leaf_clover
],
""
),
self
.
new
(
"
\u
{1F339}"
,
[
:rose
],
""
),
self
.
new
(
"
\u
{1F33B}"
,
[
:sunflower
],
""
),
self
.
new
(
"
\u
{1F33A}"
,
[
:hibiscus
],
""
),
self
.
new
(
"
\u
{1F341}"
,
[
:maple_leaf
],
""
),
self
.
new
(
"
\u
{1F343}"
,
[
:leaves
],
""
),
self
.
new
(
"
\u
{1F342}"
,
[
:fallen_leaf
],
""
),
self
.
new
(
"
\u
{1F33F}"
,
[
:herb
],
""
),
self
.
new
(
"
\u
{1F344}"
,
[
:mushroom
],
""
),
self
.
new
(
"
\u
{1F335}"
,
[
:cactus
],
""
),
self
.
new
(
"
\u
{1F334}"
,
[
:palm_tree
],
""
),
self
.
new
(
"
\u
{1F332}"
,
[
:evergreen_tree
],
""
),
self
.
new
(
"
\u
{1F333}"
,
[
:deciduous_tree
],
""
),
self
.
new
(
"
\u
{1F330}"
,
[
:chestnut
],
""
),
self
.
new
(
"
\u
{1F331}"
,
[
:seedling
],
""
),
self
.
new
(
"
\u
{1F33C}"
,
[
:blossum
],
""
),
self
.
new
(
"
\u
{1F33E}"
,
[
:ear_of_rice
],
""
),
self
.
new
(
"
\u
{1F41A}"
,
[
:shell
],
""
),
self
.
new
(
"
\u
{1F310}"
,
[
:globe_with_meridians
],
""
),
# Moon
self
.
new
(
"
\u
{1F31E}"
,
[
:sun_with_face
],
""
),
self
.
new
(
"
\u
{1F31D}"
,
[
:full_moon_with_face
],
""
),
self
.
new
(
"
\u
{1F31A}"
,
[
:new_moon_with_face
],
""
),
self
.
new
(
"
\u
{1F311}"
,
[
:new_moon
],
""
),
self
.
new
(
"
\u
{1F312}"
,
[
:waxing_crescent_moon
],
""
),
self
.
new
(
"
\u
{1F313}"
,
[
:first_quarter_moon
],
""
),
self
.
new
(
"
\u
{1F314}"
,
[
:waxing_gibbous_moon
],
""
),
self
.
new
(
"
\u
{1F315}"
,
[
:full_moon
],
""
),
self
.
new
(
"
\u
{1F316}"
,
[
:waning_gibbous_moon
],
""
),
self
.
new
(
"
\u
{1F317}"
,
[
:last_quarter_moon
],
""
),
self
.
new
(
"
\u
{1F318}"
,
[
:waning_crescent_moon
],
""
),
self
.
new
(
"
\u
{1F31C}"
,
[
:last_quarter_moon_with_face
],
""
),
self
.
new
(
"
\u
{1F31B}"
,
[
:first_quarter_moon_with_face
],
""
),
self
.
new
(
"
\u
{1F319}"
,
[
:moon
],
""
),
self
.
new
(
"
\u
{1F30D}"
,
[
:earth_africa
],
""
),
self
.
new
(
"
\u
{1F30E}"
,
[
:earth_americas
],
""
),
self
.
new
(
"
\u
{1F30F}"
,
[
:earth_asia
],
""
),
self
.
new
(
"
\u
{1F30B}"
,
[
:volcano
],
""
),
self
.
new
(
"
\u
{1F30C}"
,
[
:milky_way
],
""
),
self
.
new
(
"
\u
{26C5}"
,
[
:partly_sunny
],
""
)
]
ALL
=
PEOPLE
|
NATURE
def
self
.
find
(
symbol
)
ALL
.
find
{
|
emoji
|
emoji
.
include?
symbol
}
end
def
self
.
find_by_string
(
string
)
ALL
.
find
{
|
emoji
|
emoji
.
to_s
==
string
}
end
def
self
.
find_by_codepoint
(
codepoint
)
ALL
.
find
{
|
emoji
|
emoji
.
hex
==
codepoint
.
to_s
(
16
).
upcase
}
end
end
end
spec/rumoji/emoji_spec.rb
0 → 100644
View file @
44821e6c
# -*- encoding: utf-8 -*-
require
'rumoji'
require
'minitest/spec'
require
'minitest/autorun'
describe
Rumoji
::
Emoji
do
let
(
:symbols
)
{
[
:hankey
,
:poop
,
:shit
]
}
let
(
:name
)
{
"PILE OF POO"
}
let
(
:poo_string
)
{
"
\u
{1F4A9}"
}
subject
do
Rumoji
::
Emoji
.
new
(
poo_string
,
symbols
,
name
)
end
it
(
"has a name"
)
{
subject
.
name
.
must_equal
name
}
it
(
"has a cheat sheet code"
)
{
symbols
.
must_include
subject
.
code
}
it
(
"can test if it includes a cheat sheet code"
)
{
symbols
.
all?
{
|
symbol
|
subject
.
include?
(
symbol
)
}.
must_equal
true
}
it
(
"converts to the emoji string"
)
{
subject
.
to_s
.
must_equal
poo_string
}
it
(
"converts to a hex code"
)
{
subject
.
hex
.
must_equal
"1F4A9"
}
describe
"with multiple codepoints"
do
# From the Unicode 6.2.0 standard:
# The regional indicator symbols in the range
# U+1F1E6..U+1F1FF can be used in pairs to represent an ISO 3166 region code.
# This mechanism is not intended to supplant actual ISO 3166 region codes,
# which simply use Latin letters in the ASCII range; instead the main purpose
# of such pairs is to provide unambiguous roundtrip mappings to certain
# characters used in the emoji core sets. The representative glyph for
# region indicator symbols is simply a dotted box containing a letter. The
# Unicode Standard does not prescribe how the pairs of region indicator
# symbols should be rendered. In emoji contexts, where text is displayed
# as it would be on a Japanese mobile phone, a pair may be displayed using
# the glyph for a flag, as appropriate, but in other contexts the pair
# could be rendered differently
#
# http://www.unicode.org/versions/Unicode6.2.0/
let
(
:symbol
)
{
:us
}
let
(
:name
)
{
"REGIONAL INDICATOR SYMBOL LETTERS US"
}
let
(
:us_string
)
{
"
\xF0\x9F\x87\xBA\xF0\x9F\x87\xB8
"
}
subject
do
Rumoji
::
Emoji
.
new
(
us_string
,
symbol
,
name
)
end
it
(
"has one code"
)
{
subject
.
code
.
must_equal
symbol
}
it
(
"includes the symbol"
)
{
subject
.
must_include
symbol
}
it
(
"transforms to the correct string"
)
{
subject
.
to_s
.
must_equal
us_string
}
end
describe
"factory methods"
do
subject
{
Rumoji
::
Emoji
}
let
(
:smile_str
)
{
"
\u
{1F604}"
}
let
(
:smile_sym
)
{
:smile
}
it
"finds an emoji from cheat sheet code"
do
subject
.
find
(
smile_sym
).
to_s
.
must_equal
smile_str
end
it
"finds an emoji from a string"
do
subject
.
find_by_string
(
smile_str
).
code
.
must_equal
smile_sym
end
it
"finds an emoji from a codepoint"
do
smile_str
.
codepoints
.
map
do
|
point
|
subject
.
find_by_codepoint
(
point
).
code
.
must_equal
smile_sym
end
end
end
end
spec/rumoji_spec.rb
View file @
44821e6c
...
@@ -25,14 +25,14 @@ describe Rumoji do
...
@@ -25,14 +25,14 @@ describe Rumoji do
describe
"#encode_io"
do
describe
"#encode_io"
do
it
"reads emoji from one stream and outputs a stream of cheat-sheet codes"
do
it
"reads emoji from one stream and outputs a stream of cheat-sheet codes"
do
io
=
StringIO
.
new
(
"
#{
@smile
}
"
)
io
=
StringIO
.
new
(
"
#{
@smile
}
"
)
Rumoji
.
encode_io
(
io
).
read
.
must_equal
":smile:"
Rumoji
.
encode_io
(
io
).
string
.
must_equal
":smile:"
end
end
end
end
describe
"#decode_io"
do
describe
"#decode_io"
do
it
"reads a cheat-sheet code from one stream and outputs a stream of emoji"
do
it
"reads a cheat-sheet code from one stream and outputs a stream of emoji"
do
io
=
StringIO
.
new
(
":poop:"
)
io
=
StringIO
.
new
(
":poop:"
)
Rumoji
.
decode_io
(
io
).
read
.
must_equal
@poop
Rumoji
.
decode_io
(
io
).
string
.
must_equal
@poop
end
end
end
end
end
end
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment