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
43edb43c
Commit
43edb43c
authored
Aug 19, 2013
by
Mark Wunsch
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't lookahead for emoji, instead store previous potential emoji
A continuation of #3
parent
8df02271
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
16 deletions
+31
-16
lib/rumoji.rb
+18
-13
lib/rumoji/emoji.rb
+5
-1
lib/rumoji/emoji/symbols.rb
+2
-2
spec/rumoji_spec.rb
+6
-0
No files found.
lib/rumoji.rb
View file @
43edb43c
...
...
@@ -18,19 +18,30 @@ module Rumoji
end
def
encode_io
(
readable
,
writeable
=
StringIO
.
new
(
""
))
codepoints
=
readable
.
each_codepoint
.
entries
codepoints
.
each_with_index
do
|
codepoint
,
index
|
codepoints
=
readable
.
each_codepoint
previous_emoji
=
[]
codepoints
.
each_with_object
(
writeable
)
do
|
codepoint
,
writer
|
possible_emoji
=
Emoji
.
select_by_codepoint
(
codepoint
)
sequence
=
if
possible_emoji
.
empty?
last_emoji
=
previous_emoji
.
pop
sequence
=
if
last_emoji
.
nil?
||
!
last_emoji
.
codepoints
.
include?
(
codepoint
)
if
possible_emoji
.
empty?
[
codepoint
].
pack
(
"U"
)
elsif
possible_emoji
.
size
.
eql?
(
1
)
else
multiple_codepoint_emoji
=
possible_emoji
.
select
(
&
:multiple?
)
if
multiple_codepoint_emoji
.
empty?
possible_emoji
.
first
.
code
else
find_multipoint_emoji_in_set
(
possible_emoji
,
codepoints
[
index
+
1
])
previous_emoji
.
concat
(
multiple_codepoint_emoji
)
;
""
end
writeable
.
write
sequence
end
writeable
else
last_emoji
.
code
end
writer
.
write
sequence
end
end
def
decode_io
(
readable
,
writeable
=
StringIO
.
new
(
""
))
...
...
@@ -42,11 +53,5 @@ module Rumoji
private
def
find_multipoint_emoji_in_set
(
possible_emoji_set
,
next_codepoint
)
if
next_codepoint
emoji_or_nil
=
possible_emoji_set
.
find
{
|
emoji
|
emoji
.
codepoints
.
include?
(
next_codepoint
)
}
emoji_or_nil
.
nil?
?
""
:
emoji_or_nil
.
code
end
end
end
lib/rumoji/emoji.rb
View file @
43edb43c
...
...
@@ -38,6 +38,10 @@ module Rumoji
@codepoints
.
entries
end
def
multiple?
codepoints
.
size
>
1
end
autoload
:PEOPLE
,
'rumoji/emoji/people'
autoload
:NATURE
,
'rumoji/emoji/nature'
autoload
:OBJECTS
,
'rumoji/emoji/objects'
...
...
@@ -55,7 +59,7 @@ module Rumoji
end
def
self
.
select_by_codepoint
(
codepoint
)
ALL
.
select
{
|
emoji
|
emoji
.
codepoints
.
include
?
codepoint
}
ALL
.
select
{
|
emoji
|
emoji
.
codepoints
.
first
.
eql
?
codepoint
}
end
def
self
.
find_by_codepoint
(
codepoint
)
...
...
lib/rumoji/emoji/symbols.rb
View file @
43edb43c
...
...
@@ -86,8 +86,8 @@ module Rumoji
self
.
new
(
"
\u
{2733}"
,
[
:eight_spoked_asterisk
]),
self
.
new
(
"
\u
{1f51a}"
,
[
:end
]),
self
.
new
(
"
\u
{23e9}"
,
[
:fast_forward
]),
self
.
new
(
"
\u
{0035}"
,
[
:five
]),
self
.
new
(
"
\u
{0034}"
,
[
:four
]),
self
.
new
(
"
\u
{0035
20e3
}"
,
[
:five
]),
self
.
new
(
"
\u
{0034
20e3
}"
,
[
:four
]),
self
.
new
(
"
\u
{1f193}"
,
[
:free
]),
self
.
new
(
"
\u
{264a}"
,
[
:gemini
]),
self
.
new
(
"
\u
{0023 20e3}"
,
[
:hash
]),
...
...
spec/rumoji_spec.rb
View file @
43edb43c
...
...
@@ -38,6 +38,12 @@ describe Rumoji do
Rumoji
.
encode_io
(
io2
).
string
.
must_equal
":us:"
end
it
"transforms a stream of many emoji"
do
num
=
":one::two::three::four::five::six::seven::eight::nine::hash:"
emoji
=
StringIO
.
new
(
"1⃣2⃣3⃣4⃣5⃣6⃣7⃣8⃣9⃣#⃣"
)
Rumoji
.
encode_io
(
emoji
).
string
.
must_equal
num
end
describe
"with leading and trailing characters"
do
it
"is able to pull multipoint emoji out of a sequence"
do
io
=
StringIO
.
new
(
"An example of a multipoint emoji is the
#{
@us
}
flag."
)
...
...
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