Class: Gitlab::Dangerfiles::EmojiChecker Private
- Inherits:
-
Object
- Object
- Gitlab::Dangerfiles::EmojiChecker
- Defined in:
- lib/gitlab/dangerfiles/emoji_checker.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Constant Summary collapse
- DIGESTS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
File.("../../../fixtures/emojis/digests.json", __dir__)
- ALIASES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
File.("../../../fixtures/emojis/aliases.json", __dir__)
- LIKELY_EMOJI =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
A regex that indicates a piece of text might include an Emoji. The regex alone is not enough, as we’d match ‘:foo:bar:baz`. Instead, we use this regex to save us from having to check for all possible emoji names when we know one definitely is not included.
/:[\+a-z0-9_\-]+:/.freeze
- UNICODE_EMOJI_REGEX =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
%r{( [\u{1F300}-\u{1F5FF}] | [\u{1F1E6}-\u{1F1FF}] | [\u{2700}-\u{27BF}] | [\u{1F900}-\u{1F9FF}] | [\u{1F600}-\u{1F64F}] | [\u{1F680}-\u{1F6FF}] | [\u{2600}-\u{26FF}] )}x.freeze
Instance Method Summary collapse
- #includes_text_emoji?(text) ⇒ Boolean private
- #includes_unicode_emoji?(text) ⇒ Boolean private
-
#initialize ⇒ EmojiChecker
constructor
private
A new instance of EmojiChecker.
Constructor Details
#initialize ⇒ EmojiChecker
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of EmojiChecker.
28 29 30 31 32 33 |
# File 'lib/gitlab/dangerfiles/emoji_checker.rb', line 28 def initialize names = JSON.parse(File.read(DIGESTS)).keys + JSON.parse(File.read(ALIASES)).keys @emoji = names.map { |name| ":#{name}:" } end |
Instance Method Details
#includes_text_emoji?(text) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
35 36 37 38 39 |
# File 'lib/gitlab/dangerfiles/emoji_checker.rb', line 35 def includes_text_emoji?(text) return false unless text.match?(LIKELY_EMOJI) @emoji.any? { |emoji| text.include?(emoji) } end |
#includes_unicode_emoji?(text) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
41 42 43 |
# File 'lib/gitlab/dangerfiles/emoji_checker.rb', line 41 def includes_unicode_emoji?(text) text.match?(UNICODE_EMOJI_REGEX) end |