Commit a714f8fc by Jason Axelson

Add specs and docs for block versions

parent 2dc2c4b2
...@@ -19,8 +19,11 @@ up being lost. ...@@ -19,8 +19,11 @@ up being lost.
Rumoji.encode(str) Rumoji.encode(str)
# Takes a String, transforms Emoji into cheat-sheet codes # Takes a String, transforms Emoji into cheat-sheet codes
Rumoji.encode(str) { |emoji| #your code here }
# Takes a String, transforms Emoji into whatever you want
Rumoji.decode(str) Rumoji.decode(str)
# Does the reverse # Does the reverse of encode
Rumoji.encode_io(read, write) Rumoji.encode_io(read, write)
# For an IO pipe (a read stream, and a write stream), transform Emoji from the # For an IO pipe (a read stream, and a write stream), transform Emoji from the
...@@ -38,9 +41,11 @@ Note that rumoji has only been tested in Rubies >= 1.9!!! ...@@ -38,9 +41,11 @@ Note that rumoji has only been tested in Rubies >= 1.9!!!
### Some examples: ### Some examples:
puts Rumoji.encode("Lack of cross-device emoji support makes me 😭") puts Rumoji.encode("Lack of cross-device emoji support makes me 😭")
#=> Lack of cross-device emoji support makes me :sob: #=> Lack of cross-device emoji support makes me :sob:
Rumoji.encode_io(StringIO.new("💩")).string
#=> ":poop:"
Here's a fun file: Here's a fun file:
Rumoji.decode_io($stdin, $stdout) Rumoji.decode_io($stdin, $stdout)
...@@ -50,6 +55,37 @@ On the command line ...@@ -50,6 +55,37 @@ On the command line
echo "But Rumoji makes encoding issues a :joy:" | ruby ./funfile.rb echo "But Rumoji makes encoding issues a :joy:" | ruby ./funfile.rb
#=> But Rumoji makes encoding issues a 😂 #=> But Rumoji makes encoding issues a 😂
### Emoji methods
#### .code
The symbol of the emoji surrounded with colons
Rumoji.encode("😭") {|emoji| emoji.code}
#=> ":sob:"
#### .symbol
The symbol of the emoji surrounded with colons
Rumoji.encode("😭") {|emoji| emoji.code}
#=> "sob"
#### .multiple?
Returns true if the emoji is made up of multiple code points. E.g. 🇺🇸
Rumoji.encode("🇺🇸") {|emoji| emoji.multiple?}
#=> true
#### .string
The raw emoji
Rumoji.encode("😭") {|emoji| emoji.string}
#=> "😭"
Implement the emoji codes from emoji-cheat-sheet.com using a tool like [gemoji](https://github.com/github/gemoji) along with Rumoji, and you'll easily be able to transform user input with raw emoji unicode into images you can show to all users. Implement the emoji codes from emoji-cheat-sheet.com using a tool like [gemoji](https://github.com/github/gemoji) along with Rumoji, and you'll easily be able to transform user input with raw emoji unicode into images you can show to all users.
_Having trouble discerning what's happening in this README?_ You might be on a device with NO emoji support! All the more reason to use Rumoji. Transcode the raw unicode into something users can understand across devices! _Having trouble discerning what's happening in this README?_ You might be on a device with NO emoji support! All the more reason to use Rumoji. Transcode the raw unicode into something users can understand across devices!
......
...@@ -14,7 +14,6 @@ describe Rumoji do ...@@ -14,7 +14,6 @@ describe Rumoji do
describe "#encode" do describe "#encode" do
it "transforms emoji into cheat-sheet form" do it "transforms emoji into cheat-sheet form" do
key = :smile
Rumoji.encode(@smile).must_equal ":smile:" Rumoji.encode(@smile).must_equal ":smile:"
Rumoji.encode("#{@smile}").must_equal ":smile:" Rumoji.encode("#{@smile}").must_equal ":smile:"
end end
...@@ -56,6 +55,24 @@ describe Rumoji do ...@@ -56,6 +55,24 @@ describe Rumoji do
end end
end end
end end
describe "when passed a block" do
it "calls the block" do
Rumoji.encode(@smile) {|emoji| emoji.symbol}.must_equal "smile"
Rumoji.encode("#{@smile}") {|emoji| emoji.symbol}.must_equal "smile"
end
it "calls the block for each emoji" do
symbols = [:smile, :"flag-us"]
result = Rumoji.encode("#{@smile}#{@us}") do |emoji|
assert(emoji.class == Rumoji::Emoji)
symbols -= [emoji.symbol]
emoji.symbol
end
assert_empty(symbols)
result.must_equal "smileflag-us"
end
end
end end
describe "#decode" do describe "#decode" do
...@@ -127,6 +144,25 @@ describe Rumoji do ...@@ -127,6 +144,25 @@ describe Rumoji do
end end
end end
describe "when passed a block" do
it "calls the block" do
io = StringIO.new("I like to #{@smile}")
Rumoji.encode_io(io) {|emoji| emoji.symbol}.string.must_equal "I like to smile"
end
it "calls the block for each emoji" do
symbols = [:smile, :"flag-us"]
io = StringIO.new("first emoji: #{@smile} second: #{@us}")
result = Rumoji.encode_io(io) do |emoji|
assert(emoji.class == Rumoji::Emoji)
symbols -= [emoji.symbol]
emoji.symbol
end
assert_empty(symbols)
result.string.must_equal "first emoji: smile second: flag-us"
end
end
end end
describe "#decode_io" do describe "#decode_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