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
a6c23da9
Commit
a6c23da9
authored
May 09, 2016
by
Mark Wunsch
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #27 from delighted/avoid-excessive-symbol-creation
Avoid creating symbols based on user input
parents
74c5080a
675bf34b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
5 deletions
+19
-5
lib/rumoji.rb
+1
-1
lib/rumoji/emoji.rb
+13
-3
spec/rumoji/emoji_spec.rb
+5
-1
No files found.
lib/rumoji.rb
View file @
a6c23da9
...
@@ -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 @
a6c23da9
...
@@ -12,7 +12,11 @@ module Rumoji
...
@@ -12,7 +12,11 @@ module Rumoji
end
end
def
symbol
def
symbol
@cheat_codes
.
first
symbols
.
first
end
def
symbols
@cheat_codes
end
end
def
code
def
code
...
@@ -20,7 +24,7 @@ module Rumoji
...
@@ -20,7 +24,7 @@ module Rumoji
end
end
def
include?
(
symbol
)
def
include?
(
symbol
)
@cheat_codes
.
include?
symbol
.
to_sym
symbols
.
map
(
&
:to_s
).
include?
symbol
.
to_s
end
end
def
to_s
def
to_s
...
@@ -53,8 +57,14 @@ module Rumoji
...
@@ -53,8 +57,14 @@ module Rumoji
ALL_REGEXP
=
Regexp
.
new
(
ALL
.
map
(
&
:string
).
join
(
'|'
))
ALL_REGEXP
=
Regexp
.
new
(
ALL
.
map
(
&
:string
).
join
(
'|'
))
SYMBOL_LOOKUP
=
ALL
.
each
.
with_object
({})
do
|
emoji
,
lookup
|
emoji
.
symbols
.
each
do
|
symbol
|
lookup
[
symbol
.
to_s
]
=
emoji
end
end
def
self
.
find
(
symbol
)
def
self
.
find
(
symbol
)
ALL
.
find
{
|
emoji
|
emoji
.
include?
symbol
}
SYMBOL_LOOKUP
[
symbol
.
to_s
]
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 @
a6c23da9
...
@@ -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