tanuki_emoji 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e14e9a274c028f5da0ca9855c5ea0c15e39c67c9a555213bba590f0b72b3d072
4
+ data.tar.gz: e4c90eaabfaed8eb22c87f4097162978dec6f73edcbdf21db36cb5d2c939c587
5
+ SHA512:
6
+ metadata.gz: f06e63daa5501849456c2cf95d754286fdb41bc96283f11ada069cc9c97a2f6ea5f608f453c07f9138e7e19579857193c7ebb79d5413a65ff4832c053732c0c2
7
+ data.tar.gz: 3b3362d115678f62563757e655121e901a26c23c674da95a6a10ae7553d6d01d00609243f0a5f591f775ecb70c3588122c127e5615de50c3e1503a05424df24f
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /.idea
10
+ .rspec_status
11
+ /*.gem
12
+
13
+ # rspec failure tracking
14
+ .rspec_status
data/.gitlab-ci.yml ADDED
@@ -0,0 +1,36 @@
1
+ .ruby: &ruby
2
+ variables:
3
+ LANG: "C.UTF-8"
4
+ before_script:
5
+ - ruby -v # Print out ruby version for debugging
6
+ - gem install bundler --no-document # Bundler is not installed with the image
7
+ - bundle config set --local path 'vendor'
8
+ - bundle install -j $(nproc) # Install dependencies into ./vendor/ruby
9
+ parallel:
10
+ matrix:
11
+ - RUBY_VERSION: ['2.7', '3.0']
12
+ image: "ruby:$RUBY_VERSION"
13
+ cache:
14
+ paths:
15
+ - vendor/ruby
16
+ key: 'ruby$RUBY_VERSION'
17
+
18
+ rspec:
19
+ extends: .ruby
20
+ script:
21
+ - bundle exec rake spec
22
+ artifacts:
23
+ reports:
24
+ junit: rspec.xml
25
+ cobertura: coverage/coverage.xml
26
+
27
+ rubocop:
28
+ extends: .ruby
29
+ script:
30
+ - bundle exec rake rubocop
31
+
32
+ include:
33
+ - template: SAST.gitlab-ci.yml
34
+ - template: Dependency-Scanning.gitlab-ci.yml
35
+ - template: Security/License-Scanning.gitlab-ci.yml
36
+ - template: Code-Quality.gitlab-ci.yml
data/.idea/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ # Default ignored files
2
+ /shelf/
3
+ /workspace.xml
4
+ # Datasource local storage ignored files
5
+ /dataSources/
6
+ /dataSources.local.xml
7
+ # Editor-based HTTP Client requests
8
+ /httpRequests/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,19 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.7
3
+ Exclude:
4
+ - '*.gemspec'
5
+ - 'vendor/**/*'
6
+ SuggestExtensions: false
7
+
8
+ Style/StringLiterals:
9
+ Enabled: false
10
+
11
+ Style/StringLiteralsInInterpolation:
12
+ Enabled: true
13
+ EnforcedStyle: double_quotes
14
+
15
+ Layout/LineLength:
16
+ Max: 140
17
+
18
+ Metrics:
19
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [0.1.0] - 2021-07-04
10
+ ### Added
11
+ - Initial release with index and Character information support
12
+
13
+ [0.1.0]:https://gitlab.com/brodock/tanuki_emoji/-/releases/v0.1.0
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gemspec
6
+
7
+ gem "rake", "~> 13.0"
8
+ gem "rspec", "~> 3.0"
9
+ gem "rspec_junit_formatter", "~> 0.4.0"
10
+ gem "rubocop", "~> 1.7"
11
+ gem "simplecov", require: false
12
+ gem "simplecov-cobertura", "~> 1.4.2"
data/Gemfile.lock ADDED
@@ -0,0 +1,69 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ tanuki_emoji (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.2)
10
+ diff-lcs (1.4.4)
11
+ docile (1.4.0)
12
+ parallel (1.20.1)
13
+ parser (3.0.2.0)
14
+ ast (~> 2.4.1)
15
+ rainbow (3.0.0)
16
+ rake (13.0.6)
17
+ regexp_parser (2.1.1)
18
+ rexml (3.2.5)
19
+ rspec (3.10.0)
20
+ rspec-core (~> 3.10.0)
21
+ rspec-expectations (~> 3.10.0)
22
+ rspec-mocks (~> 3.10.0)
23
+ rspec-core (3.10.1)
24
+ rspec-support (~> 3.10.0)
25
+ rspec-expectations (3.10.1)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.10.0)
28
+ rspec-mocks (3.10.2)
29
+ diff-lcs (>= 1.2.0, < 2.0)
30
+ rspec-support (~> 3.10.0)
31
+ rspec-support (3.10.2)
32
+ rspec_junit_formatter (0.4.1)
33
+ rspec-core (>= 2, < 4, != 2.12.0)
34
+ rubocop (1.18.4)
35
+ parallel (~> 1.10)
36
+ parser (>= 3.0.0.0)
37
+ rainbow (>= 2.2.2, < 4.0)
38
+ regexp_parser (>= 1.8, < 3.0)
39
+ rexml
40
+ rubocop-ast (>= 1.8.0, < 2.0)
41
+ ruby-progressbar (~> 1.7)
42
+ unicode-display_width (>= 1.4.0, < 3.0)
43
+ rubocop-ast (1.8.0)
44
+ parser (>= 3.0.1.1)
45
+ ruby-progressbar (1.11.0)
46
+ simplecov (0.21.2)
47
+ docile (~> 1.1)
48
+ simplecov-html (~> 0.11)
49
+ simplecov_json_formatter (~> 0.1)
50
+ simplecov-cobertura (1.4.2)
51
+ simplecov (~> 0.8)
52
+ simplecov-html (0.12.3)
53
+ simplecov_json_formatter (0.1.3)
54
+ unicode-display_width (2.0.0)
55
+
56
+ PLATFORMS
57
+ x86_64-darwin-20
58
+
59
+ DEPENDENCIES
60
+ rake (~> 13.0)
61
+ rspec (~> 3.0)
62
+ rspec_junit_formatter (~> 0.4.0)
63
+ rubocop (~> 1.7)
64
+ simplecov
65
+ simplecov-cobertura (~> 1.4.2)
66
+ tanuki_emoji!
67
+
68
+ BUNDLED WITH
69
+ 2.2.9
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 GitLab B.V.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,71 @@
1
+ # Tanuki Emoji
2
+
3
+ This library helps you implement Emoji support in a ruby application by providing you access to native Emoji character
4
+ information.
5
+
6
+ We currently provides a pre-indexed set of Emojis, compatible with [Gemojione](https://github.com/bonusly/gemojione)
7
+ index from 3.3.0. In the future we expect to cover the most recent version of Unicode.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'tanuki_emoji'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ ```shell
20
+ $ bundle install
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ To access the index and list all known Emoji Characters:
26
+
27
+ ```ruby
28
+ TanukiEmoji.index.all
29
+ ```
30
+
31
+ To search for an Emoji by it's codepoints (the unicode character):
32
+
33
+ ```ruby
34
+ # Find by providing the Emoji Character itself
35
+ TanukiEmoji.find_by_codepoints('🐴')
36
+ #=> #<TanukiEmoji::Character:horse 🐴(1f434)>
37
+
38
+ # Find by providing a string representation of the hexadecimal of the codepoint:
39
+ TanukiEmoji.find_by_codepoints("\u{1f434}")
40
+ #=> #<TanukiEmoji::Character:horse 🐴(1f434)>
41
+ ```
42
+
43
+ To search for an Emoji by it's `:alpha_code:`
44
+
45
+ ```ruby
46
+ # Find by providing the :alpha_code:
47
+ TanukiEmoji.find_by_alpha_code(':horse:')
48
+ #=> #<TanukiEmoji::Character:horse 🐴(1f434)>
49
+
50
+ # It also accepts a `shortcode` (an alpha_code not surrounded by colons)
51
+ TanukiEmoji.find_by_alpha_code('horse')
52
+ #=> #<TanukiEmoji::Character:horse 🐴(1f434)>
53
+ ```
54
+
55
+ ## Development
56
+
57
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests.
58
+ You can also run `bin/console` for an interactive prompt that will allow you to experiment.
59
+
60
+ To install this gem onto your local machine, run `bundle exec rake install`.
61
+ To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`,
62
+ which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to
63
+ [rubygems.org](https://rubygems.org).
64
+
65
+ ## Contributing
66
+
67
+ Bug reports and pull requests are welcome on GitLab at https://gitlab.com/brodock/tanuki_emoji.
68
+
69
+ ## License
70
+
71
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+ require "rubocop/rake_task"
6
+
7
+ RSpec::Core::RakeTask.new(:spec) do |t|
8
+ t.rspec_opts = %w[--format documentation --color --require spec_helper]
9
+ t.rspec_opts += %w[--format RspecJunitFormatter --out rspec.xml] if ENV['GITLAB_CI']
10
+ end
11
+
12
+ RuboCop::RakeTask.new
13
+
14
+ task default: %i[spec rubocop]
15
+
16
+ desc 'Code coverage detail'
17
+ task :simplecov do
18
+ ENV['COVERAGE'] = 'true'
19
+ Rake::Task['spec'].execute
20
+ end
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "tanuki_emoji"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Tanuki Emoji
4
+ module TanukiEmoji
5
+ autoload :VERSION, './lib/tanuki_emoji/version'
6
+ autoload :Error, './lib/tanuki_emoji/errors'
7
+ autoload :AlphaCodeAlreadyIndexedError, './lib/tanuki_emoji/errors'
8
+ autoload :CodepointAlreadyIndexedError, './lib/tanuki_emoji/errors'
9
+ autoload :Index, './lib/tanuki_emoji/index'
10
+ autoload :Character, './lib/tanuki_emoji/character'
11
+ autoload :Db, './lib/tanuki_emoji/db'
12
+
13
+ # This denotes a "color" or "emoji" version
14
+ EMOJI_VARIATION_SELECTOR = 0xFE0F
15
+ # This denotes a "plain" (black/white) or "textual" version
16
+ PLAIN_VARIATION_SELECTOR = 0xFE0E
17
+ BASE_FLAG_TAG = 0x1F3F4
18
+ # Zero Width Joiner is used in sequences to indicate they should all be evaluated and displayed as a single thing
19
+ ZWJ_TAG = 0x200D
20
+
21
+ # Find an Emoji by its :alpha_code:
22
+ #
23
+ # @param [String] alpha_code
24
+ # @return [TanukiEmoji::Character]
25
+ def self.find_by_alpha_code(alpha_code)
26
+ index.find_by_alpha_code(alpha_code)
27
+ end
28
+
29
+ # Find an Emoji by its Unicode representation
30
+ #
31
+ # @param [String] unicode_codepoints
32
+ # @return [TanukiEmoji::Character]
33
+ def self.find_by_codepoints(unicode_codepoints)
34
+ index.find_by_codepoints(unicode_codepoints)
35
+ end
36
+
37
+ # Index contains all known emojis
38
+ #
39
+ # @return [Array<TanukiEmoji::Character>]
40
+ def self.index
41
+ TanukiEmoji::Index.instance
42
+ end
43
+
44
+ # Add a new Emoji to the index
45
+ #
46
+ # @param [String] name
47
+ # @param [String] codepoints
48
+ # @param [String] alpha_code
49
+ def self.add(name, codepoints:, alpha_code:, description:)
50
+ emoji = Character.new(name, codepoints: codepoints, alpha_code: alpha_code, description: description)
51
+
52
+ index.add(emoji)
53
+ end
54
+ end
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TanukiEmoji
4
+ # Character represents an Emoji character or sequence which can be formed by one or more Unicode code points
5
+ # respectively which combined form a unique pictographic representation (known as Emoji)
6
+ #
7
+ # @see https://www.unicode.org/reports/tr51/
8
+ class Character
9
+ attr_reader :name, :codepoints, :codepoints_alternates, :alpha_code, :aliases, :description
10
+
11
+ # @param [String] name
12
+ # @param [String] codepoints
13
+ # @param [String] alpha_code
14
+ def initialize(name, codepoints:, alpha_code:, description:)
15
+ @name = name
16
+ @codepoints = codepoints
17
+ @codepoints_alternates = []
18
+ @alpha_code = self.class.format_alpha_code(alpha_code)
19
+ @aliases = []
20
+ @description = description
21
+ end
22
+
23
+ # Add alternative codepoints to this character
24
+ #
25
+ # @param [String] codepoints
26
+ def add_codepoints(codepoints)
27
+ codepoints_alternates << codepoints
28
+ end
29
+
30
+ # Add alternative alpha_codes to this character
31
+ #
32
+ # @param [String] alpha_code
33
+ def add_alias(alpha_code)
34
+ aliases << self.class.format_alpha_code(alpha_code)
35
+ end
36
+
37
+ # Return a Hex formatted version of the Unicode code points
38
+ #
39
+ # @return [String] Hex formatted version of the unicode
40
+ def hex
41
+ unicode_to_hex(codepoints).join('-')
42
+ end
43
+
44
+ def to_s
45
+ codepoints
46
+ end
47
+
48
+ def inspect
49
+ "#<#{self.class.name}:#{name} #{codepoints}(#{hex})>"
50
+ end
51
+
52
+ # Convert Unicode code points to Hex format for inspection
53
+ #
54
+ # ensure alpha code is formatted with colons
55
+ #
56
+ # @param [String] alpha_code
57
+ # @return [String] formatted alpha code
58
+ def self.format_alpha_code(alpha_code)
59
+ alpha_code.match?(/:([a-z_0-9]+):/) ? alpha_code : ":#{alpha_code}:"
60
+ end
61
+
62
+ private
63
+
64
+ # Return each codepoint converted to its hex value as string
65
+ #
66
+ # @param [String] value
67
+ # @return [Array<String>] hex value as string
68
+ def unicode_to_hex(value)
69
+ value.unpack('U*').map { |i| i.to_s(16).rjust(4, '0') }
70
+ end
71
+ end
72
+ end