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
ca7af064
Commit
ca7af064
authored
Jan 31, 2013
by
Mark Wunsch
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
An emoji can print its own cheat sheet code
parent
325970fd
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
7 deletions
+14
-7
lib/rumoji.rb
+4
-2
lib/rumoji/emoji.rb
+5
-1
spec/rumoji/emoji_spec.rb
+5
-4
No files found.
lib/rumoji.rb
View file @
ca7af064
...
@@ -6,14 +6,16 @@ require 'stringio'
...
@@ -6,14 +6,16 @@ require 'stringio'
module
Rumoji
module
Rumoji
extend
self
extend
self
# Transform emoji into its cheat-sheet code
def
encode
(
str
)
def
encode
(
str
)
remapped_codepoints
=
str
.
codepoints
.
flat_map
do
|
codepoint
|
remapped_codepoints
=
str
.
codepoints
.
flat_map
do
|
codepoint
|
emoji
=
Emoji
.
find_by_codepoint
(
codepoint
)
emoji
=
Emoji
.
find_by_codepoint
(
codepoint
)
emoji
?
":
#{
emoji
.
code
}
:"
.
codepoints
.
entries
:
codepoint
emoji
?
emoji
.
code
.
codepoints
.
entries
:
codepoint
end
end
remapped_codepoints
.
pack
(
"U*"
)
remapped_codepoints
.
pack
(
"U*"
)
end
end
# Transform a cheat-sheet code into an Emoji
def
decode
(
str
)
def
decode
(
str
)
str
.
gsub
(
/:(\S?\w+):/
)
{
|
sym
|
Emoji
.
find
(
$1
.
intern
).
to_s
}
str
.
gsub
(
/:(\S?\w+):/
)
{
|
sym
|
Emoji
.
find
(
$1
.
intern
).
to_s
}
end
end
...
@@ -21,7 +23,7 @@ module Rumoji
...
@@ -21,7 +23,7 @@ module Rumoji
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
=
Emoji
.
find_by_codepoint
(
codepoint
)
emoji
=
Emoji
.
find_by_codepoint
(
codepoint
)
emoji_or_character
=
emoji
?
":
#{
emoji
.
code
}
:"
:
[
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
writeable
...
...
lib/rumoji/emoji.rb
View file @
ca7af064
...
@@ -10,10 +10,14 @@ module Rumoji
...
@@ -10,10 +10,14 @@ module Rumoji
@name
=
name
||
@cheat_codes
.
first
.
to_s
.
upcase
.
gsub
(
"_"
,
" "
)
@name
=
name
||
@cheat_codes
.
first
.
to_s
.
upcase
.
gsub
(
"_"
,
" "
)
end
end
def
code
def
symbol
@cheat_codes
.
first
@cheat_codes
.
first
end
end
def
code
":
#{
symbol
}
:"
end
def
include?
(
symbol
)
def
include?
(
symbol
)
@cheat_codes
.
include?
symbol
.
to_sym
@cheat_codes
.
include?
symbol
.
to_sym
end
end
...
...
spec/rumoji/emoji_spec.rb
View file @
ca7af064
...
@@ -13,7 +13,7 @@ describe Rumoji::Emoji do
...
@@ -13,7 +13,7 @@ describe Rumoji::Emoji do
end
end
it
(
"has a name"
)
{
subject
.
name
.
must_equal
name
}
it
(
"has a name"
)
{
subject
.
name
.
must_equal
name
}
it
(
"has a cheat sheet code"
)
{
symbols
.
must_include
subject
.
code
}
it
(
"has a cheat sheet code"
)
{
symbols
.
must_include
subject
.
code
[
1
...-
1
].
intern
}
it
(
"can test if it includes a cheat sheet code"
)
{
symbols
.
all?
{
|
symbol
|
subject
.
include?
(
symbol
)
}.
must_equal
true
}
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 the emoji string"
)
{
subject
.
to_s
.
must_equal
poo_string
}
it
(
"converts to a hex code"
)
{
subject
.
hex
.
must_equal
"1F4A9"
}
it
(
"converts to a hex code"
)
{
subject
.
hex
.
must_equal
"1F4A9"
}
...
@@ -51,7 +51,8 @@ describe Rumoji::Emoji do
...
@@ -51,7 +51,8 @@ describe Rumoji::Emoji do
Rumoji
::
Emoji
.
new
(
us_string
,
symbol
,
name
)
Rumoji
::
Emoji
.
new
(
us_string
,
symbol
,
name
)
end
end
it
(
"has one code"
)
{
subject
.
code
.
must_equal
symbol
}
it
(
"has one symbol, representing the code"
)
{
subject
.
symbol
.
must_equal
symbol
}
it
(
"has one cheat sheet code"
)
{
subject
.
code
[
1
...-
1
].
intern
.
must_equal
symbol
}
it
(
"includes the symbol"
)
{
subject
.
must_include
symbol
}
it
(
"includes the symbol"
)
{
subject
.
must_include
symbol
}
it
(
"transforms to the correct string"
)
{
subject
.
to_s
.
must_equal
us_string
}
it
(
"transforms to the correct string"
)
{
subject
.
to_s
.
must_equal
us_string
}
end
end
...
@@ -66,12 +67,12 @@ describe Rumoji::Emoji do
...
@@ -66,12 +67,12 @@ describe Rumoji::Emoji do
end
end
it
"finds an emoji from a string"
do
it
"finds an emoji from a string"
do
subject
.
find_by_string
(
smile_str
).
code
.
must_equal
smile_sym
subject
.
find_by_string
(
smile_str
).
symbol
.
must_equal
smile_sym
end
end
it
"finds an emoji from a codepoint"
do
it
"finds an emoji from a codepoint"
do
smile_str
.
codepoints
.
map
do
|
point
|
smile_str
.
codepoints
.
map
do
|
point
|
subject
.
find_by_codepoint
(
point
).
code
.
must_equal
smile_sym
subject
.
find_by_codepoint
(
point
).
symbol
.
must_equal
smile_sym
end
end
end
end
end
end
...
...
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