emoji_sub 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,28 @@
1
+ require_relative 'lib/emoji_sub/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "emoji_sub"
5
+ spec.version = EmojiSub::VERSION
6
+ spec.authors = ["Aaron Hill"]
7
+ spec.email = ["armahillo@gmail.com"]
8
+
9
+ spec.summary = %q{Replace your Slack short_code emoji with unicode equivalents}
10
+ spec.description = %q{EmojiSub allows you to use :short_code_emoji: in your text and quickly replace it with the natural Unicode versions via a bit of string parsing logic}
11
+ spec.homepage = "https://github.com/armahillo/emoji_sub"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+ spec.metadata["homepage_uri"] = spec.homepage
16
+ spec.metadata["source_code_uri"] = "https://github.com/armahillo/emoji_sub"
17
+ spec.metadata["changelog_uri"] = "https://github.com/armahillo/emoji_sub/blob/master/CHANGELOG.md"
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ end
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+
28
+ end
@@ -0,0 +1,24 @@
1
+ require "emoji_sub/version"
2
+ require 'YAML'
3
+
4
+ module EmojiSub
5
+ EMOJI_MAPPING_YAML = "data/emoji.yaml"
6
+
7
+ def emoji_sub(text, additional_mappings = {})
8
+ known_emoji = YAML.load(File.read(EMOJI_MAPPING_YAML)).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}:/, "&#x#{unicode}")
17
+ end
18
+
19
+ text
20
+ end
21
+ module_function :emoji_sub
22
+
23
+
24
+ end
@@ -0,0 +1,25 @@
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)
@@ -0,0 +1,3 @@
1
+ module EmojiSub
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: emoji_sub
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Aaron Hill
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-08-22 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: 'EmojiSub allows you to use :short_code_emoji: in your text and quickly
14
+ replace it with the natural Unicode versions via a bit of string parsing logic'
15
+ email:
16
+ - armahillo@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".gitignore"
22
+ - ".rspec"
23
+ - ".travis.yml"
24
+ - CHANGELOG.md
25
+ - CODE_OF_CONDUCT.md
26
+ - Gemfile
27
+ - Gemfile.lock
28
+ - LICENSE.txt
29
+ - README.md
30
+ - Rakefile
31
+ - bin/console
32
+ - bin/setup
33
+ - data/emoji.yaml
34
+ - emoji_sub.gemspec
35
+ - lib/emoji_sub.rb
36
+ - lib/emoji_sub/emoji_parser.rb
37
+ - lib/emoji_sub/version.rb
38
+ homepage: https://github.com/armahillo/emoji_sub
39
+ licenses:
40
+ - MIT
41
+ metadata:
42
+ homepage_uri: https://github.com/armahillo/emoji_sub
43
+ source_code_uri: https://github.com/armahillo/emoji_sub
44
+ changelog_uri: https://github.com/armahillo/emoji_sub/blob/master/CHANGELOG.md
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 2.3.0
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubygems_version: 3.1.2
61
+ signing_key:
62
+ specification_version: 4
63
+ summary: Replace your Slack short_code emoji with unicode equivalents
64
+ test_files: []