emoji-regex 0.1.0 → 0.1.1

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
  SHA1:
3
- metadata.gz: edfcf4b0f99966f3383647592cc6476ba81987ab
4
- data.tar.gz: 350ae4ba0a7739ecbada3be6f676b2f84b4a9ea4
3
+ metadata.gz: aff4ba19125ff68b4dbc92ba6a9ecb43051200c5
4
+ data.tar.gz: e6c10bdca195eb5f7bf40f6738b5d8f7e23bbb2e
5
5
  SHA512:
6
- metadata.gz: cd8ebeb0a23c6b13fed77edb3e2baf519ad18ee92b84dcb43ea92caff50663ced62079c2dadc4ab626530609ae5440bf79651496ca9ec8949fea53d8b7207525
7
- data.tar.gz: 53648372e78593c6464acc0d37e743433c32433ee8b76c15fdda1f2f53a2f798c3cc3aa24f9b36cddec7ada188782fa9c02d2a0c36f888c0b1d61b7f48231fba
6
+ metadata.gz: 85e0d80a9e3f5616dca5a9b988356b7907dc23eb8869733b55184717b10fbdd09388477ef27cd1b59f1f931975f51d9735b6c2864bd24211b2c00c285db21184
7
+ data.tar.gz: f760cc56558bf8c6105705f527fee4ce0a6fa7ebb8e9b9e46c299f912ad1540afa5112537715e14a32f2a274d0365922e711d476c23190527e079cde5c156c8a
@@ -16,7 +16,6 @@ Gem::Specification.new do |spec|
16
16
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
17
  f.match(%r{^(test|spec|features)/})
18
18
  end
19
-
20
19
  spec.bindir = 'exe'
21
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
21
  spec.require_paths = ['lib']
@@ -2,20 +2,37 @@ require 'open-uri'
2
2
 
3
3
  module EmojiRegex
4
4
  class Fetcher
5
- SOURCE = 'http://www.unicode.org/Public/emoji/1.0/emoji-data.txt'.freeze
5
+ SOURCE = 'https://www.unicode.org/Public/emoji/6.0/emoji-data.txt'.freeze
6
6
 
7
7
  def initialize
8
- @emoji_code = open(SOURCE, &:read).split("\n").map { |x| x.split(" ;\t")[0] }
9
8
  @emoji_file_path = File.join(Dir.tmpdir, 'sorted_emoji.txt')
10
9
  end
11
10
 
12
11
  def save
13
- @emoji_file.tap do
14
- lines = @emoji_code.map { |line| line if line[0] != '#' }.compact.join("\n")
12
+ emoji_file = open(SOURCE, &:read)
13
+ emoji_code_lines = emoji_file.split("\n").map { |x| x.split(' ;')[0] }.compact.map(&:rstrip)
15
14
 
16
- File.write(@emoji_file_path, lines)
15
+ emoji_codes = emoji_code_lines.each_with_object([]) do |line, result|
16
+ case line
17
+ when /^#/
18
+ nil
19
+ when /^(0023|002A|0030)/
20
+ nil
21
+ when /^.{4,5}\.\./
22
+ start_code_hex, end_code_hex = line.split('..')
23
+ base_10_code_range = (start_code_hex.to_i(16)..end_code_hex.to_i(16))
24
+ hex_codes = base_10_code_range.to_a.map { |base_10_code| base_10_code.to_s(16).rjust(4, '0').upcase }
25
+ hex_codes.each { |code| result << code }
26
+ else
27
+ result << line
28
+ end
29
+ end
30
+
31
+ File.open(@emoji_file_path, 'w') do |f|
32
+ f << emoji_codes.uniq.join("\n")
17
33
  end
18
34
  end
35
+
19
36
  alias update save
20
37
 
21
38
  def saved_path
@@ -2,47 +2,47 @@ module EmojiRegex
2
2
  class Maker
3
3
  def initialize
4
4
  @input_file_path = Fetcher.new.saved_path
5
- @prev = -1
6
- @prev_hex = ''
7
- @left = ''
8
- @ranges = []
5
+ end
6
+
7
+ def regex
8
+ regex = ranges.map do |e|
9
+ l = e[0]
10
+ r = e[1]
11
+ next if l == '' || r == '' || !l[/\s/].nil? || !r[/\s/].nil?
12
+ if l == r
13
+ "\\u{#{l}}"
14
+ else
15
+ "\\u{#{l}}-\\u{#{r}}"
16
+ end
17
+ end
18
+ regex.unshift '['
19
+ regex.push ']'
20
+
21
+ Regexp.new(regex.join)
9
22
  end
10
23
 
11
24
  def ranges
12
- ranges =
13
- File.open(@input_file_path).map do |line|
14
- hex = line.to_i(16)
25
+ prev = -1
26
+ prev_hex = ''
27
+ left = ''
15
28
 
16
- if [@prev, @prev + 1].include?(hex)
17
- @prev, @prev_hex = [hex, line.chomp] && next
18
- else
19
- [@left, @prev_hex].tap do
20
- @left = line.chomp
21
- @prev = hex
22
- @prev_hex = @left
23
- end
24
- end
29
+ ranges = File.open(@input_file_path).map do |line|
30
+ hex = line.to_i(16)
31
+ if hex == prev || hex == prev + 1
32
+ prev = hex
33
+ prev_hex = line.chomp
34
+ next
25
35
  end
36
+ range = [left, prev_hex]
37
+ left = line.chomp
38
+ prev = hex
39
+ prev_hex = left
40
+ range
41
+ end
26
42
 
27
43
  ranges
28
44
  .compact
29
- .reject { |ary| ary[0].empty? || ary[1].empty? }
30
- end
31
-
32
- def regex
33
- regex = '[' +
34
- ranges.map do |range|
35
- left = range[0]
36
- right = range[1]
37
- next if left == '' || right == '' || !left[/\s/].nil? || !right[/\s/].nil?
38
-
39
- if left == right
40
- "\\u{#{left}}"
41
- else
42
- "\\u{#{left}}-\\u{#{right}}"
43
- end
44
- end.join + ']'
45
- Regexp.new(regex)
45
+ .reject { |a, b| a.empty? || b.empty? }
46
46
  end
47
47
  end
48
48
  end
@@ -1,3 +1,3 @@
1
1
  module EmojiRegex
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.1.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: emoji-regex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Satoshi Ohmori
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-09-11 00:00:00.000000000 Z
11
+ date: 2017-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -121,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
121
  version: '0'
122
122
  requirements: []
123
123
  rubyforge_project:
124
- rubygems_version: 2.5.2
124
+ rubygems_version: 2.5.2.1
125
125
  signing_key:
126
126
  specification_version: 4
127
127
  summary: Make regex for latest unicode emoji.