-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #2 - Adds monkey patching for string
- Loading branch information
Showing
7 changed files
with
75 additions
and
4 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
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,19 @@ | ||
module CoreExtensions | ||
module EmojiSub | ||
## | ||
# This monkey patches String so that it can receive emoji_sub directives | ||
# cf. https://github.com/armahillo/emoji_sub/issues/2 | ||
# If you want to monkey patch your use of String, you should be able to include | ||
# this module and that should do it. | ||
## | ||
module String | ||
def emoji_sub(options = {}) | ||
::EmojiSub.emoji_sub(self, options) | ||
end | ||
|
||
def emoji_sub!(options = {}) | ||
replace emoji_sub(options) | ||
end | ||
end | ||
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 |
---|---|---|
|
@@ -24,5 +24,4 @@ def emoji_definitions | |
end | ||
|
||
module_function :emoji_sub, :emoji_definitions | ||
|
||
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module EmojiSub | ||
VERSION = "0.2.2" | ||
VERSION = "0.3.0" | ||
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
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,35 @@ | ||
require 'core_extensions/string' | ||
|
||
RSpec.describe String do | ||
before(:each) do | ||
String.prepend CoreExtensions::EmojiSub::String | ||
end | ||
|
||
subject { "I :heartbeat: NY" } | ||
|
||
describe "emoji_sub" do | ||
it { is_expected.to be_respond_to(:emoji_sub) } | ||
|
||
it "replaces the shortcodes with their corresponding unicode" do | ||
expect(subject.emoji_sub).to eq('I 💓 NY') | ||
end | ||
|
||
it "allows an override to be provided as an argument" do | ||
expect(subject.emoji_sub({ heartbeat: "1111" })).to eq('I ᄑ NY') | ||
end | ||
end | ||
|
||
describe "emoji_sub!" do | ||
it { is_expected.to be_respond_to(:emoji_sub!) } | ||
|
||
it "replaces in-place with the corresponding unicode" do | ||
subject.emoji_sub! | ||
expect(subject).to eq('I 💓 NY') | ||
end | ||
|
||
it "allows an override to be provided as an argument" do | ||
subject.emoji_sub!({ heartbeat: "1111" }) | ||
expect(subject).to eq('I ᄑ NY') | ||
end | ||
end | ||
end |