emoji-datasource 7.0.2 → 14.0.1
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/.github/workflows/main.yml +13 -12
- data/.gitignore +1 -0
- data/.rubocop.yml +1 -1
- data/LICENSE +1 -1
- data/README.md +25 -2
- data/emoji-datasource.gemspec +5 -4
- data/lib/emoji_datasource/emoji.rb +57 -10
- data/lib/emoji_datasource/version.rb +1 -1
- data/lib/emoji_datasource.rb +61 -6
- data/package.json +1 -1
- data/vendor/emoji-datasource/emoji.json +1 -1
- data/yarn.lock +4 -4
- metadata +11 -12
- data/Gemfile.lock +0 -70
- data/lib/emoji_datasource/short_name_to_char.rb +0 -49
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b821544f15170c9489e0ce8938978549829e3c925d3ec6444dfacb7c125b94ca
|
4
|
+
data.tar.gz: bf4e9c21d3c5ea9de80132de4aa56bfec68c705aba979863151d650facc73f77
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 03d5041a86c4d7bccde94965634abffd3194c7cc3dcfa70e1de6f573ea1b6d444c6382cc0275b88165597247dd1e97f1ced2050ca671c51183fcb62412a8dcea
|
7
|
+
data.tar.gz: 994db50c5e4221bf51ed491d108d0b3fb48dea1fae2837d3129d39586d8eb7d080e0423bec5aac775eba4ffc0360299bd20cb64b607f4333c0b9f36a6b2805f2
|
data/.github/workflows/main.yml
CHANGED
@@ -7,37 +7,38 @@ jobs:
|
|
7
7
|
name: Test
|
8
8
|
strategy:
|
9
9
|
matrix:
|
10
|
-
ruby: [2.
|
10
|
+
ruby: [2.6, 2.7, '3.0', 3.1, head]
|
11
11
|
|
12
12
|
runs-on: ubuntu-latest
|
13
13
|
|
14
14
|
steps:
|
15
|
-
-
|
15
|
+
- name: Checkout
|
16
|
+
uses: actions/checkout@v3
|
17
|
+
|
16
18
|
- name: Set up Ruby ${{ matrix.ruby }}
|
17
19
|
uses: ruby/setup-ruby@v1
|
18
20
|
with:
|
19
21
|
ruby-version: ${{ matrix.ruby }}
|
20
|
-
|
21
|
-
|
22
|
-
gem install bundler
|
23
|
-
bundle install --jobs 4 --retry 3
|
22
|
+
bundler-cache: true
|
23
|
+
|
24
24
|
- name: RSpec
|
25
25
|
run: |
|
26
26
|
bundle exec rspec
|
27
|
+
|
27
28
|
rubocop:
|
28
29
|
name: RuboCop
|
29
30
|
runs-on: ubuntu-latest
|
30
31
|
|
31
32
|
steps:
|
32
|
-
-
|
33
|
+
- name: Checkout
|
34
|
+
uses: actions/checkout@v3
|
35
|
+
|
33
36
|
- name: Set up Ruby
|
34
37
|
uses: ruby/setup-ruby@v1
|
35
38
|
with:
|
36
|
-
ruby-version:
|
37
|
-
|
38
|
-
|
39
|
-
gem install bundler
|
40
|
-
bundle install --jobs 4 --retry 3
|
39
|
+
ruby-version: 3.1
|
40
|
+
bundler-cache: true
|
41
|
+
|
41
42
|
- name: RuboCop
|
42
43
|
run: |
|
43
44
|
bundle exec rubocop
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -22,6 +22,21 @@ Find emoji by short name
|
|
22
22
|
|
23
23
|
```ruby
|
24
24
|
EmojiDatasource.find_by_short_name('+1')
|
25
|
+
#=> EmojiDatasource::Emoji: :+1: (👍)
|
26
|
+
```
|
27
|
+
|
28
|
+
Find emoji by raw string:
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
EmojiDatasource.find_by_char('👍🏾')
|
32
|
+
#=> EmojiDatasource::Emoji: :+1::skin-tone-5: (👍🏾)
|
33
|
+
```
|
34
|
+
|
35
|
+
Find emoji by unicode hex character code:
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
EmojiDatasource.find_by_unified("1F469-200D-2764-FE0F-200D-1F468")
|
39
|
+
#=> EmojiDatasource::Emoji: :woman-heart-man: (👩❤️👨)
|
25
40
|
```
|
26
41
|
|
27
42
|
Convert emoji short name to character
|
@@ -33,19 +48,27 @@ EmojiDatasource.short_name_to_char('+1') # => 👍
|
|
33
48
|
this also supports skin variations
|
34
49
|
|
35
50
|
```ruby
|
36
|
-
EmojiDatasource.short_name_to_char('+1::skin-tone-2') # =>
|
51
|
+
EmojiDatasource.short_name_to_char('+1::skin-tone-2') # => 👍🏻
|
37
52
|
```
|
38
53
|
|
54
|
+
Get base emoji for skin variation:
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
emoji = EmojiDatasource.find_by_short_name(':+1::skin-tone-5:')
|
58
|
+
#=> EmojiDatasource::Emoji: :+1::skin-tone-5: (👍🏾)
|
59
|
+
emoji.base
|
60
|
+
#=> EmojiDatasource::Emoji: :+1: (👍)
|
61
|
+
```
|
39
62
|
|
40
63
|
## Supported Ruby Versions
|
41
64
|
|
42
65
|
This library aims to support and is [tested against][github_actions] the following Ruby
|
43
66
|
implementations:
|
44
67
|
|
45
|
-
* Ruby 2.5.0
|
46
68
|
* Ruby 2.6.0
|
47
69
|
* Ruby 2.7.0
|
48
70
|
* Ruby 3.0.0
|
71
|
+
* Ruby 3.1.0
|
49
72
|
|
50
73
|
## License
|
51
74
|
|
data/emoji-datasource.gemspec
CHANGED
@@ -13,12 +13,13 @@ Gem::Specification.new do |spec|
|
|
13
13
|
'(https://github.com/iamcal/emoji-data) npm package'
|
14
14
|
spec.homepage = 'http://github.com/jpalumickas/emoji-datasource-ruby'
|
15
15
|
spec.license = 'MIT'
|
16
|
-
spec.required_ruby_version = Gem::Requirement.new('>= 2.
|
16
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.6.0')
|
17
17
|
|
18
18
|
spec.metadata['homepage_uri'] = spec.homepage
|
19
19
|
spec.metadata['source_code_uri'] = 'https://github.com/jpalumickas/emoji-datasource-ruby'
|
20
20
|
spec.metadata['changelog_uri'] = 'https://github.com/jpalumickas/emoji-datasource-ruby/releases'
|
21
21
|
spec.metadata['bug_tracker_uri'] = 'https://github.com/jpalumickas/emoji-datasource-ruby/issues'
|
22
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
22
23
|
|
23
24
|
# Specify which files should be added to the gem when it is released.
|
24
25
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
@@ -33,7 +34,7 @@ Gem::Specification.new do |spec|
|
|
33
34
|
|
34
35
|
spec.add_development_dependency 'pry', '~> 0.14'
|
35
36
|
spec.add_development_dependency 'rake', '~> 13.0'
|
36
|
-
spec.add_development_dependency 'rspec', '~> 3.
|
37
|
-
spec.add_development_dependency 'rubocop', '~> 1.
|
38
|
-
spec.add_development_dependency 'simplecov', '~> 0.
|
37
|
+
spec.add_development_dependency 'rspec', '~> 3.12'
|
38
|
+
spec.add_development_dependency 'rubocop', '~> 1.45'
|
39
|
+
spec.add_development_dependency 'simplecov', '~> 0.22'
|
39
40
|
end
|
@@ -2,38 +2,75 @@
|
|
2
2
|
|
3
3
|
module EmojiDatasource
|
4
4
|
class Emoji
|
5
|
-
attr_reader :data
|
5
|
+
attr_reader :data, :unified
|
6
6
|
|
7
|
-
def initialize(data)
|
7
|
+
def initialize(data, variation: nil)
|
8
8
|
@data = data
|
9
|
+
@variation = variation
|
10
|
+
@unified = variation ? @data.dig('skin_variations', variation, 'unified') : @data['unified']
|
9
11
|
end
|
10
12
|
|
13
|
+
# Raw emoji string
|
11
14
|
def to_char
|
12
|
-
EmojiDatasource.unified_to_char(
|
15
|
+
EmojiDatasource.unified_to_char(unified)
|
13
16
|
end
|
14
17
|
|
15
|
-
|
16
|
-
|
18
|
+
# Official emoji name (pretty long)
|
19
|
+
def name
|
20
|
+
return @data['name'] unless @variation
|
17
21
|
|
18
|
-
@data[
|
22
|
+
"#{@data['name']} (#{variation_emojis.map(&:name).join(', ')})"
|
23
|
+
end
|
24
|
+
|
25
|
+
# Short code that often can be used to find emoji in pickers and chat apps
|
26
|
+
def short_name
|
27
|
+
return @data['short_name'] unless @variation
|
28
|
+
|
29
|
+
"#{@data['short_name']}::#{variation_emojis.map(&:short_name).join('::')}"
|
30
|
+
end
|
31
|
+
|
32
|
+
# All known short names (base +short_name+ and maybe some aliases)
|
33
|
+
def short_names
|
34
|
+
return @data['short_names'] unless @variation
|
35
|
+
|
36
|
+
@data['short_names'].map do |short_name|
|
37
|
+
"#{short_name}::#{variation_emojis.map(&:short_name).join('::')}"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# All known skin tone variations
|
42
|
+
def variations
|
43
|
+
return @variations = [] if @variation
|
44
|
+
|
45
|
+
@variations ||= @data.fetch('skin_variations', {}).each_key.map do |key|
|
46
|
+
self.class.new(data, variation: key)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Base emoji, without variations applied.
|
51
|
+
# E.g. for `:+1::skin-tone-2:` base will be just `:+1:`
|
52
|
+
def base
|
53
|
+
return self unless @variation
|
54
|
+
|
55
|
+
EmojiDatasource.find_by_unified(@data['unified'])
|
19
56
|
end
|
20
57
|
|
21
58
|
def method_missing(method_name, *arguments, &block)
|
22
|
-
if @data.key?(method_name)
|
23
|
-
@data[method_name]
|
59
|
+
if @data.key?(method_name.to_s)
|
60
|
+
@data[method_name.to_s]
|
24
61
|
else
|
25
62
|
super
|
26
63
|
end
|
27
64
|
end
|
28
65
|
|
29
66
|
def respond_to_missing?(method_name, include_private = false)
|
30
|
-
return true if @data.key?(method_name)
|
67
|
+
return true if @data.key?(method_name.to_s)
|
31
68
|
|
32
69
|
super
|
33
70
|
end
|
34
71
|
|
35
72
|
def inspect
|
36
|
-
"#{self.class.name}:#{short_name}"
|
73
|
+
"#{self.class.name}: :#{short_name}: (#{to_char})"
|
37
74
|
end
|
38
75
|
|
39
76
|
def to_s
|
@@ -47,5 +84,15 @@ module EmojiDatasource
|
|
47
84
|
def to_json(**args)
|
48
85
|
@data.to_json(**args)
|
49
86
|
end
|
87
|
+
|
88
|
+
private
|
89
|
+
|
90
|
+
def variation_emojis
|
91
|
+
return [] unless @variation
|
92
|
+
|
93
|
+
@variation.split('-').map do |unified|
|
94
|
+
EmojiDatasource.find_by_unified(unified)
|
95
|
+
end
|
96
|
+
end
|
50
97
|
end
|
51
98
|
end
|
data/lib/emoji_datasource.rb
CHANGED
@@ -4,23 +4,50 @@ require 'json'
|
|
4
4
|
|
5
5
|
require_relative 'emoji_datasource/version'
|
6
6
|
require_relative 'emoji_datasource/emoji'
|
7
|
-
require_relative 'emoji_datasource/short_name_to_char'
|
8
7
|
|
9
8
|
module EmojiDatasource
|
10
9
|
class Error < StandardError; end
|
11
10
|
|
12
11
|
EMOJI_DATA_PATH = File.join(__dir__, '..', 'vendor', 'emoji-datasource', 'emoji.json')
|
13
12
|
|
13
|
+
# @example
|
14
|
+
# short_name_to_char('+1') #=> "👍"
|
14
15
|
def self.short_name_to_char(name)
|
15
|
-
|
16
|
+
find_by_short_name(name)&.to_char
|
16
17
|
end
|
17
18
|
|
19
|
+
# Finds emoji by short code (e.g. `+1`, `:+1:`, `:+1::skin-tone-5:`)
|
20
|
+
# @param name [String] short code with or without wrapping colons.
|
21
|
+
# @return [EmojiDatasource::Emoji] if there is an emoji matching +name+
|
22
|
+
# @return [nil] if there are no emojis matching +name+
|
23
|
+
# @example
|
24
|
+
# find_by_short_name('+1') #=> EmojiDatasource::Emoji: :+1: (👍)
|
18
25
|
def self.find_by_short_name(name)
|
19
26
|
return unless name
|
20
27
|
|
21
|
-
|
22
|
-
|
23
|
-
|
28
|
+
name = name.delete_prefix(':').delete_suffix(':') # Allow to find `+1` by `:+1:`
|
29
|
+
name.delete_suffix!('::skin-tone-1') # special case for default skin tone
|
30
|
+
short_name_lookup_map[name]
|
31
|
+
end
|
32
|
+
|
33
|
+
# Finds emoji by unified hex representation of Unicode codepoints
|
34
|
+
# @param unified [String] Dash separated hexadecimal Unicode character codes for a single emoji
|
35
|
+
# @return [EmojiDatasource::Emoji] if given Unicode codepoints is a known emoji
|
36
|
+
# @return [nil] if there are no emojis with given codepoints in the dataset
|
37
|
+
# @example
|
38
|
+
# short_name_to_char('1F44D') #=> EmojiDatasource::Emoji: :+1: (👍)
|
39
|
+
def self.find_by_unified(unified)
|
40
|
+
unified_lookup_map[unified.upcase]
|
41
|
+
end
|
42
|
+
|
43
|
+
# Find emoji object by raw Unicode string with a single emoji in it
|
44
|
+
# @param raw_emoji [String] Single emoji
|
45
|
+
# @return [EmojiDatasource::Emoji] if given string contains a single known emoji
|
46
|
+
# @return [nil] if there are no such emoji in the dataset
|
47
|
+
# @example
|
48
|
+
# find_by_char('👍') #=> EmojiDatasource::Emoji: :+1: (👍)
|
49
|
+
def self.find_by_char(raw_emoji)
|
50
|
+
find_by_unified(char_to_unified(raw_emoji))
|
24
51
|
end
|
25
52
|
|
26
53
|
def self.unified_to_char(unified_name)
|
@@ -29,10 +56,38 @@ module EmojiDatasource
|
|
29
56
|
unified_name.split('-').map(&:hex).pack('U*')
|
30
57
|
end
|
31
58
|
|
59
|
+
def self.char_to_unified(raw_emoji)
|
60
|
+
return unless raw_emoji
|
61
|
+
|
62
|
+
raw_emoji.unpack('U*').map { |c| c.to_s(16).upcase }.join('-')
|
63
|
+
end
|
64
|
+
|
32
65
|
def self.data
|
33
|
-
@data ||= JSON.parse(File.read(EMOJI_DATA_PATH)
|
66
|
+
@data ||= JSON.parse(File.read(EMOJI_DATA_PATH))
|
34
67
|
.map { |emoji_data| EmojiDatasource::Emoji.new(emoji_data) }
|
35
68
|
end
|
69
|
+
|
70
|
+
# Utility hash map to search by emoji short code, including variants
|
71
|
+
# @api private
|
72
|
+
def self.short_name_lookup_map
|
73
|
+
@short_name_lookup_map ||= data.each_with_object({}) do |emoji, result|
|
74
|
+
emoji.short_names.each { |short_name| result[short_name] = emoji }
|
75
|
+
emoji.variations.each do |emoji_variant|
|
76
|
+
emoji_variant.short_names.each { |short_name| result[short_name] = emoji_variant }
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# Utility hash map to search by unicode character sequence hex codes, including variants
|
82
|
+
# @api private
|
83
|
+
def self.unified_lookup_map
|
84
|
+
@unified_lookup_map ||= data.each_with_object({}) do |emoji, result|
|
85
|
+
result[emoji.unified] = emoji
|
86
|
+
emoji.variations.each do |emoji_variant|
|
87
|
+
result[emoji_variant.unified] = emoji_variant
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
36
91
|
end
|
37
92
|
|
38
93
|
# Preload emojies on startup
|
data/package.json
CHANGED