emoji_sub 0.2.1 → 0.5.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.
data/emoji_sub.gemspec CHANGED
@@ -1,4 +1,4 @@
1
- require_relative 'lib/emoji_sub/version'
1
+ require_relative 'lib/emoji_sub'
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "emoji_sub"
@@ -21,8 +21,8 @@ Gem::Specification.new do |spec|
21
21
  spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
22
22
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec|lib\/development)/}) }
23
23
  end
24
- spec.bindir = "exe"
25
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
24
  spec.require_paths = ["lib"]
27
25
 
28
26
  end
27
+
28
+
@@ -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,30 +1,8 @@
1
- require "emoji_sub/version"
2
- require 'yaml'
3
-
4
1
  module EmojiSub
5
- EMOJI_MAPPING_YAML = "data/emoji.yaml"
6
-
7
- def emoji_sub(text, additional_mappings = {})
8
- known_emoji = emoji_definitions.merge(additional_mappings)
9
-
10
- discovered_emoji = text.scan(/:([\w\d\-\_]+):/).flatten.map(&:to_sym).uniq
11
- found = discovered_emoji.each_with_object({}) do |emoji, found|
12
- found[emoji] = known_emoji.fetch(emoji,nil)
13
- end.compact
14
-
15
- found.each do |shortcode, unicode|
16
- text.gsub!(/:#{shortcode}:/, Array(unicode).map { |u| "&#x#{u}" }.join(''))
17
- end
18
-
19
- text
20
- end
21
-
22
- def emoji_definitions
23
- m = YAML.load(File.read(EMOJI_MAPPING_YAML)).values
24
- @emoji_definitions ||= m.inject({}) { |a,memo| memo.merge(a) }
25
-
26
- #@emoji_definitions ||= m.collect(&:values).flatten
27
- end
28
- module_function :emoji_sub, :emoji_definitions
2
+ GEM_ROOT = File.dirname(__FILE__) + "/.."
3
+ EMOJI_MAPPING_YAML = GEM_ROOT + "/data/emoji.yaml"
4
+ end
29
5
 
30
- end
6
+ require_relative 'emoji_sub/version'
7
+ require_relative 'emoji_sub/definitions'
8
+ require_relative 'emoji_sub/emoji_sub'
@@ -0,0 +1,10 @@
1
+ require 'yaml'
2
+
3
+ module EmojiSub
4
+ extend self
5
+ def definitions
6
+ @emoji_definitions ||= YAML.load(File.read(EMOJI_MAPPING_YAML))
7
+ end
8
+
9
+ module_function :definitions
10
+ end
@@ -0,0 +1,19 @@
1
+ module EmojiSub
2
+ extend self
3
+ def emoji_sub(text, additional_mappings = {})
4
+ known_emoji = definitions.merge(additional_mappings)
5
+
6
+ discovered_emoji = text.scan(/:([\w\d\-\_]+):/).flatten.map(&:to_sym).uniq
7
+ found = discovered_emoji.each_with_object({}) do |emoji, found|
8
+ found[emoji] = known_emoji.fetch(emoji,nil)
9
+ end.compact
10
+
11
+ found.each do |shortcode, unicode|
12
+ text.gsub!(/:#{shortcode}:/, Array(unicode).map { |u| "&#x#{u}" }.join(''))
13
+ end
14
+
15
+ text
16
+ end
17
+
18
+ module_function :emoji_sub
19
+ end
@@ -1,3 +1,3 @@
1
1
  module EmojiSub
2
- VERSION = "0.2.1"
2
+ VERSION = "0.5.0"
3
3
  end
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.2.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Hill
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-22 00:00:00.000000000 Z
11
+ date: 2021-08-17 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,7 +32,10 @@ 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
37
+ - lib/emoji_sub/definitions.rb
38
+ - lib/emoji_sub/emoji_sub.rb
36
39
  - lib/emoji_sub/version.rb
37
40
  homepage: https://github.com/armahillo/emoji_sub
38
41
  licenses: