twemoji 3.1.5 → 3.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d66c0459eba2a74b47f2dc8027c9696e4a19fccbb4e4734340f0f77667da4cd9
4
- data.tar.gz: 377cdea67fe500c751f9e1cc050706305ff50251d68153074530687b75b36698
3
+ metadata.gz: e70cd3f6a86f43f8095ec186477bd936b5d2b3c7a5af5283a595efc659d72774
4
+ data.tar.gz: 0daa9a7069e81018cb6d3bba2073e8264de794113d1e7ee83b95f9bd8c7b94e6
5
5
  SHA512:
6
- metadata.gz: 6ab7a53adcceda2450fb78793696f7c067274d4fbc756c8f1574bc4739df042d324bece5276ea449bc87fb5cfd154e85efc2b71934c14ef721cda25247291aa6
7
- data.tar.gz: 29dee191ffe0551c6eccec1c43a194732e3d8f31c5f2e3b7fc3e08f32064068a95caa7fd3bb65224030e59dcc55ff469c363da9fdedc61ea006021dd1de7b40d
6
+ metadata.gz: 922a3572d45c1c1615bd73701bad2d548518b34eb88ec430b823c56d7ca304bca4cf7ec7ba0cca47f9d3cdf2004bc0ebf066267c5d8806865f149c9c7f64679d
7
+ data.tar.gz: 23200ed2aa135f1847265b7a85a8dedbef265af703b0d923e20f16e3c870565782ed27310552d7991d8923cb6d1e54de60f296cd008d42106cc764402fa0a96b
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 3.1.5 - 2019.12.21
6
+
7
+ - Moved expensive computations to constant [#53](https://github.com/jollygoodcode/twemoji/pull/53)
8
+
5
9
  ## 3.1.5 - 2019.06.02
6
10
 
7
11
  - Introduced `Twemoji::Utils::Unicode.unpack` [#51](https://github.com/jollygoodcode/twemoji/pull/51)
data/lib/twemoji.rb CHANGED
@@ -126,7 +126,7 @@ module Twemoji
126
126
  #
127
127
  # @return [RegExp] A Regular expression consists of all emojis text.
128
128
  def self.emoji_pattern
129
- @emoji_pattern ||= /(#{codes.keys.map { |name| Regexp.quote(name) }.join("|") })/
129
+ EMOJI_PATTERN
130
130
  end
131
131
 
132
132
  # Return all emoji patterns' regular expressions in unicode.
@@ -134,21 +134,31 @@ module Twemoji
134
134
  #
135
135
  # @return [RegExp] A Regular expression consists of all emojis unicode.
136
136
  def self.emoji_pattern_unicode
137
- @emoji_pattern_unicode ||= /(#{sorted_codepoint_values.map { |name| Regexp.quote(name.split('-').collect {|n| n.hex}.pack("U*")) }.join("|") })/
137
+ EMOJI_PATTERN_UNICODE
138
138
  end
139
139
 
140
140
  # Return all emoji patterns' regular expressions in unicode and name.
141
141
  #
142
142
  # @return [RegExp] A Regular expression consists of all emojis unicode codepoint and names.
143
143
  def self.emoji_pattern_all
144
- names = codes.keys.map { |name| Regexp.quote(name) }.join("|")
145
- codepoints = sorted_codepoint_values.map { |name| Regexp.quote(name.split('-').collect {|n| n.hex}.pack("U*")) }.join("|")
146
-
147
- @emoji_pattern_all ||= /(#{names}|#{codepoints})/
144
+ EMOJI_PATTERN_ALL
148
145
  end
149
146
 
150
147
  private
151
148
 
149
+ # Return sorted codepoint values by descending length.
150
+ #
151
+ # @return [Array] An array of emoji codepoint values sorted by descending length
152
+ def self.sorted_codepoint_values
153
+ # has to be sorted to match the combined codepoint (2-3 char emojis) before single char emojis
154
+ @sorted_codepoint_values ||= invert_codes.keys.sort_by {|key| key.length }.reverse
155
+ end
156
+
157
+ EMOJI_PATTERN = /#{codes.keys.map { |name| Regexp.quote(name) }.join("|")}/.freeze
158
+ EMOJI_PATTERN_UNICODE = /#{sorted_codepoint_values.map { |name| Regexp.quote(name.split('-').collect {|n| n.hex}.pack("U*")) }.join("|")}/.freeze
159
+ EMOJI_PATTERN_ALL = /(#{EMOJI_PATTERN}|#{EMOJI_PATTERN_UNICODE})/.freeze
160
+ private_constant :EMOJI_PATTERN, :EMOJI_PATTERN_UNICODE, :EMOJI_PATTERN_ALL
161
+
152
162
  # Ensure text is a string.
153
163
  #
154
164
  # @param text [String] Text to ensure to be a string.
@@ -321,12 +331,4 @@ module Twemoji
321
331
  def self.hash_to_html_attrs(hash)
322
332
  hash.reject { |key, value| value.nil? || value == '' }.map { |attr, value| %(#{attr}="#{value}") }.join(" ")
323
333
  end
324
-
325
- # Return sorted codepoint values by descending length.
326
- #
327
- # @return [Array] An array of emoji codepoint values sorted by descending length
328
- def self.sorted_codepoint_values
329
- # has to be sorted to match the combined codepoint (2-3 char emojis) before single char emojis
330
- @sorted_codepoint_values ||= invert_codes.keys.sort_by {|key| key.length }.reverse
331
- end
332
334
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Twemoji
4
- VERSION = "3.1.5"
4
+ VERSION = "3.1.6"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twemoji
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.5
4
+ version: 3.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juanito
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-06-02 00:00:00.000000000 Z
12
+ date: 2019-12-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -71,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
71
71
  - !ruby/object:Gem::Version
72
72
  version: '0'
73
73
  requirements: []
74
- rubygems_version: 3.0.3
74
+ rubygems_version: 3.1.2
75
75
  signing_key:
76
76
  specification_version: 4
77
77
  summary: 'A RubyGem to convert :heart: to Twitter cdn url'