Commit a6896619 by Mark Wunsch

Merge pull request #8 from mirego/fix/regex-dash

Make decode regex work with codes that have dashes in them
parents c3b98d3d 45ee9867
...@@ -14,7 +14,7 @@ module Rumoji ...@@ -14,7 +14,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).to_s } str.gsub(/:(\S?[\w-]+):/) {|sym| Emoji.find($1.intern).to_s }
end end
def encode_io(readable, writeable=StringIO.new("")) def encode_io(readable, writeable=StringIO.new(""))
......
...@@ -9,6 +9,7 @@ describe Rumoji do ...@@ -9,6 +9,7 @@ describe Rumoji do
@smile = "😄" @smile = "😄"
@zero = "0⃣" @zero = "0⃣"
@us = "🇺🇸" @us = "🇺🇸"
@non_potable_water = "🚱"
end end
describe "#encode" do describe "#encode" do
...@@ -22,6 +23,10 @@ describe Rumoji do ...@@ -22,6 +23,10 @@ describe Rumoji do
it "transforms a cheat-sheet code into an emoji" do it "transforms a cheat-sheet code into an emoji" do
Rumoji.decode(":poop:").must_equal @poop Rumoji.decode(":poop:").must_equal @poop
end end
it "transforms a cheat-sheet code with a dash into an emoji" do
Rumoji.decode(":non-potable_water:").must_equal @non_potable_water
end
end end
describe "#encode_io" do describe "#encode_io" do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment