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
e7b6c0d9
Commit
e7b6c0d9
authored
Oct 31, 2012
by
Mark Wunsch
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Read emoji/codes in and out of IO
parent
8e8e7652
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
4 deletions
+41
-4
lib/rumoji.rb
+22
-0
spec/rumoji_spec.rb
+19
-4
No files found.
lib/rumoji.rb
View file @
e7b6c0d9
# -*- encoding: utf-8 -*-
# -*- encoding: utf-8 -*-
require
"rumoji/version"
require
"rumoji/version"
require
'stringio'
module
Rumoji
module
Rumoji
extend
self
extend
self
...
@@ -20,6 +21,27 @@ module Rumoji
...
@@ -20,6 +21,27 @@ module Rumoji
duplicate
duplicate
end
end
def
encode_io
(
input
,
output
=
StringIO
.
new
(
""
))
input
.
each_codepoint
do
|
codepoint
|
emoji
=
codepoint
.
to_s
(
16
).
upcase
emoji_or_character
=
EMOJI_NAME_TO_CODEPOINT
.
has_value?
(
emoji
)
?
":
#{
EMOJI_NAME_TO_CODEPOINT
.
key
(
emoji
)
}
:"
:
[
codepoint
].
pack
(
"U"
)
output
.
write
emoji_or_character
end
output
.
rewind
output
end
def
decode_io
(
input
,
output
=
StringIO
.
new
(
""
))
input
.
each
do
|
word
|
EMOJI_NAME_TO_CODEPOINT
.
each_pair
do
|
key
,
value
|
word
.
gsub!
(
":
#{
key
}
:"
,
[
value
.
to_i
(
16
)].
pack
(
"U"
))
end
output
.
write
(
word
)
end
output
.
rewind
output
end
EMOJI_NAME_TO_CODEPOINT
=
{
EMOJI_NAME_TO_CODEPOINT
=
{
# PEOPLE
# PEOPLE
smile:
"1F604"
,
smile:
"1F604"
,
...
...
spec/rumoji_spec.rb
View file @
e7b6c0d9
...
@@ -5,20 +5,34 @@ require 'minitest/autorun'
...
@@ -5,20 +5,34 @@ require 'minitest/autorun'
describe
Rumoji
do
describe
Rumoji
do
before
do
before
do
@emoji_map
=
Hash
[
Rumoji
::
EMOJI_NAME_TO_CODEPOINT
.
map
{
|
k
,
v
|
[
k
,
[
v
.
to_i
(
16
)].
pack
(
"U"
)]
}]
@poop
=
"💩"
@smile
=
"😄"
end
end
describe
"#encode"
do
describe
"#encode"
do
it
"transforms emoji into cheat-sheet form"
do
it
"transforms emoji into cheat-sheet form"
do
key
=
:smile
key
=
:smile
Rumoji
.
encode
(
"
#{
@emoji_map
[
key
]
}
"
).
must_equal
":
#{
key
}
:"
Rumoji
.
encode
(
@smile
).
must_equal
":smile
:"
end
end
end
end
describe
"#decode"
do
describe
"#decode"
do
it
"transforms a cheat-sheet code into an emoji"
do
it
"transforms a cheat-sheet code into an emoji"
do
poop_emoji
=
"💩"
Rumoji
.
decode
(
":poop:"
).
must_equal
@poop
Rumoji
.
decode
(
":poop:"
).
must_equal
"
#{
poop_emoji
}
"
end
end
describe
"#encode_io"
do
it
"reads emoji from one stream and outputs a stream of cheat-sheet codes"
do
io
=
StringIO
.
new
(
"
#{
@smile
}
"
)
Rumoji
.
encode_io
(
io
).
read
.
must_equal
":smile:"
end
end
describe
"#decode_io"
do
it
"reads a cheat-sheet code from one stream and outputs a stream of emoji"
do
io
=
StringIO
.
new
(
":poop:"
)
Rumoji
.
decode_io
(
io
).
read
.
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