emoji_sub 0.1.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/CHANGELOG.md +36 -1
- data/Gemfile +8 -0
- data/Gemfile.lock +47 -1
- data/README.md +12 -2
- data/Rakefile +22 -0
- data/data/emoji.yaml +9034 -1048
- data/emoji_sub.gemspec +1 -1
- data/lib/core_extensions/string.rb +19 -0
- data/lib/emoji_sub.rb +7 -4
- data/lib/emoji_sub/version.rb +1 -1
- metadata +3 -3
- data/lib/emoji_sub/emoji_parser.rb +0 -25
data/emoji_sub.gemspec
CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
# Specify which files should be added to the gem when it is released.
|
20
20
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
21
21
|
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
22
|
-
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(
|
22
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec|lib\/development)/}) }
|
23
23
|
end
|
24
24
|
spec.bindir = "exe"
|
25
25
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module CoreExtensions
|
2
|
+
module EmojiSub
|
3
|
+
##
|
4
|
+
# This monkey patches String so that it can receive emoji_sub directives
|
5
|
+
# cf. https://github.com/armahillo/emoji_sub/issues/2
|
6
|
+
# If you want to monkey patch your use of String, you should be able to include
|
7
|
+
# this module and that should do it.
|
8
|
+
##
|
9
|
+
module String
|
10
|
+
def emoji_sub(options = {})
|
11
|
+
::EmojiSub.emoji_sub(self, options)
|
12
|
+
end
|
13
|
+
|
14
|
+
def emoji_sub!(options = {})
|
15
|
+
replace emoji_sub(options)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/emoji_sub.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
require "emoji_sub/version"
|
2
|
-
require '
|
2
|
+
require 'yaml'
|
3
3
|
|
4
4
|
module EmojiSub
|
5
5
|
EMOJI_MAPPING_YAML = "data/emoji.yaml"
|
6
6
|
|
7
7
|
def emoji_sub(text, additional_mappings = {})
|
8
|
-
known_emoji =
|
8
|
+
known_emoji = emoji_definitions.merge(additional_mappings)
|
9
9
|
|
10
10
|
discovered_emoji = text.scan(/:([\w\d\-\_]+):/).flatten.map(&:to_sym).uniq
|
11
11
|
found = discovered_emoji.each_with_object({}) do |emoji, found|
|
@@ -13,12 +13,15 @@ module EmojiSub
|
|
13
13
|
end.compact
|
14
14
|
|
15
15
|
found.each do |shortcode, unicode|
|
16
|
-
text.gsub!(/:#{shortcode}:/, "&#x#{
|
16
|
+
text.gsub!(/:#{shortcode}:/, Array(unicode).map { |u| "&#x#{u}" }.join(''))
|
17
17
|
end
|
18
18
|
|
19
19
|
text
|
20
20
|
end
|
21
|
-
module_function :emoji_sub
|
22
21
|
|
22
|
+
def emoji_definitions
|
23
|
+
@emoji_definitions ||= YAML.load(File.read(EMOJI_MAPPING_YAML))
|
24
|
+
end
|
23
25
|
|
26
|
+
module_function :emoji_sub, :emoji_definitions
|
24
27
|
end
|
data/lib/emoji_sub/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: emoji_sub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Hill
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-10-06 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: 'EmojiSub allows you to use :short_code_emoji: in your text and quickly
|
14
14
|
replace it with the natural Unicode versions via a bit of string parsing logic'
|
@@ -32,8 +32,8 @@ files:
|
|
32
32
|
- bin/setup
|
33
33
|
- data/emoji.yaml
|
34
34
|
- emoji_sub.gemspec
|
35
|
+
- lib/core_extensions/string.rb
|
35
36
|
- lib/emoji_sub.rb
|
36
|
-
- lib/emoji_sub/emoji_parser.rb
|
37
37
|
- lib/emoji_sub/version.rb
|
38
38
|
homepage: https://github.com/armahillo/emoji_sub
|
39
39
|
licenses:
|
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'YAML'
|
2
|
-
|
3
|
-
def emoji_sub(text)
|
4
|
-
known_emoji = load_emoji
|
5
|
-
discovered_emoji = text.scan(/:([\w\d\-\_]+):/).flatten.map(&:to_sym).uniq
|
6
|
-
found = discovered_emoji.each_with_object({}) do |emoji, found|
|
7
|
-
found[emoji] = known_emoji.fetch(emoji,'')
|
8
|
-
end
|
9
|
-
|
10
|
-
found.each do |shortcode, unicode|
|
11
|
-
text.gsub!(/:#{shortcode}:/, "&#x#{unicode}")
|
12
|
-
end
|
13
|
-
|
14
|
-
text
|
15
|
-
end
|
16
|
-
|
17
|
-
def load_emoji
|
18
|
-
YAML.load(File.read('emoji.yaml'))
|
19
|
-
end
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
TEXT = 'This is testing text :100: :100: :100: :bad_dude: It is great :slightly_smiling_face:.'
|
24
|
-
|
25
|
-
p emoji_sub(TEXT)
|