Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from wpeterson/feature/string_helper
Add opt-in String helper methods
- Loading branch information
Showing
3 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class String | ||
def with_emoji_images | ||
Emoji.replace_unicode_moji_with_images(self) | ||
end | ||
|
||
def image_url | ||
Emoji.image_url_for_name(self.emoji_data['name']) | ||
end | ||
|
||
def emoji_data | ||
index = Emoji.index | ||
index.find_by_moji(self) || index.find_by_name(self) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# encoding: UTF-8 | ||
|
||
require 'emoji/string_ext' | ||
|
||
describe String, 'with Emoji extensions' do | ||
describe '#with_emoji_images' do | ||
it 'should replace unicode moji with an img tag' do | ||
base_string = "I ❤ Emoji" | ||
replaced_string = base_string.with_emoji_images | ||
assert_equal "I <img class=\"emoji\" src=\"http://localhost:3000/heart.png\"> Emoji", replaced_string | ||
end | ||
end | ||
|
||
describe '#image_url' do | ||
it 'should generate image_url' do | ||
assert_equal 'http://localhost:3000/cyclone.png', '🌀'.image_url | ||
assert_equal 'http://localhost:3000/cyclone.png', 'cyclone'.image_url | ||
end | ||
end | ||
|
||
describe '#emoji_data' do | ||
it 'should find data for a name or a moji' do | ||
data_from_moji = '❤'.emoji_data | ||
data_from_string = 'heart'.emoji_data | ||
|
||
assert_equal data_from_moji, data_from_string | ||
end | ||
end | ||
end |