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
9cbd04d2
Commit
9cbd04d2
authored
May 05, 2016
by
Ben Turner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't convert all input to symbols during lookup
parent
065d5901
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
4 deletions
+11
-4
lib/rumoji.rb
+1
-1
lib/rumoji/emoji.rb
+5
-2
spec/rumoji/emoji_spec.rb
+5
-1
No files found.
lib/rumoji.rb
View file @
9cbd04d2
...
@@ -13,7 +13,7 @@ module Rumoji
...
@@ -13,7 +13,7 @@ module Rumoji
# Transform a cheat-sheet code into an Emoji
# Transform a cheat-sheet code into an Emoji
def
decode
(
str
)
def
decode
(
str
)
str
.
gsub
(
/:([^\s:]?[\w-]+):/
)
{
|
sym
|
(
Emoji
.
find
(
$1
.
intern
)
||
sym
).
to_s
}
str
.
gsub
(
/:([^\s:]?[\w-]+):/
)
{
|
match
|
(
Emoji
.
find
(
$1
)
||
match
).
to_s
}
end
end
def
encode_io
(
readable
,
writeable
=
StringIO
.
new
(
""
))
def
encode_io
(
readable
,
writeable
=
StringIO
.
new
(
""
))
...
...
lib/rumoji/emoji.rb
View file @
9cbd04d2
...
@@ -20,7 +20,7 @@ module Rumoji
...
@@ -20,7 +20,7 @@ module Rumoji
end
end
def
include?
(
symbol
)
def
include?
(
symbol
)
@cheat_codes
.
include?
symbol
.
to_sym
@cheat_codes
.
map
(
&
:to_s
).
include?
symbol
.
to_s
end
end
def
to_s
def
to_s
...
@@ -53,8 +53,11 @@ module Rumoji
...
@@ -53,8 +53,11 @@ module Rumoji
ALL_REGEXP
=
Regexp
.
new
(
ALL
.
map
(
&
:string
).
join
(
'|'
))
ALL_REGEXP
=
Regexp
.
new
(
ALL
.
map
(
&
:string
).
join
(
'|'
))
FIND_BY_SYMBOL_CACHE
=
{}
def
self
.
find
(
symbol
)
def
self
.
find
(
symbol
)
ALL
.
find
{
|
emoji
|
emoji
.
include?
symbol
}
symbol
=
symbol
.
to_s
FIND_BY_SYMBOL_CACHE
[
symbol
]
||=
ALL
.
find
{
|
emoji
|
emoji
.
include?
symbol
}
end
end
STRING_LOOKUP
=
ALL
.
each
.
with_object
({})
do
|
emoji
,
lookup
|
STRING_LOOKUP
=
ALL
.
each
.
with_object
({})
do
|
emoji
,
lookup
|
...
...
spec/rumoji/emoji_spec.rb
View file @
9cbd04d2
...
@@ -62,10 +62,14 @@ describe Rumoji::Emoji do
...
@@ -62,10 +62,14 @@ describe Rumoji::Emoji do
let
(
:smile_str
)
{
"
\u
{1F604}"
}
let
(
:smile_str
)
{
"
\u
{1F604}"
}
let
(
:smile_sym
)
{
:smile
}
let
(
:smile_sym
)
{
:smile
}
it
"finds an emoji from cheat sheet code"
do
it
"finds an emoji from cheat sheet code
symbol
"
do
subject
.
find
(
smile_sym
).
to_s
.
must_equal
smile_str
subject
.
find
(
smile_sym
).
to_s
.
must_equal
smile_str
end
end
it
"finds an emoji from cheat sheet code string"
do
subject
.
find
(
smile_sym
.
to_s
).
to_s
.
must_equal
smile_str
end
it
"finds an emoji from a string"
do
it
"finds an emoji from a string"
do
subject
.
find_by_string
(
smile_str
).
symbol
.
must_equal
smile_sym
subject
.
find_by_string
(
smile_str
).
symbol
.
must_equal
smile_sym
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