emoji-regex 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,6 @@
1
+ module EmojiRegex
2
+ end
3
+
4
+ require 'emoji-regex/version'
5
+ require 'emoji-regex/fetcher'
6
+ require 'emoji-regex/maker'
@@ -0,0 +1,27 @@
1
+ require 'open-uri'
2
+
3
+ module EmojiRegex
4
+ class Fetcher
5
+ SOURCE = 'http://www.unicode.org/Public/emoji/1.0/emoji-data.txt'.freeze
6
+
7
+ def initialize
8
+ @emoji_code = open(SOURCE, &:read).split("\n").map { |x| x.split(" ;\t")[0] }
9
+ @emoji_file_path = File.join(Dir.tmpdir, 'sorted_emoji.txt')
10
+ end
11
+
12
+ def save
13
+ @emoji_file.tap do
14
+ lines = @emoji_code.map { |line| line if line[0] != '#' }.compact.join("\n")
15
+
16
+ File.write(@emoji_file_path, lines)
17
+ end
18
+ end
19
+ alias update save
20
+
21
+ def saved_path
22
+ save unless File.exist?(@emoji_file_path)
23
+
24
+ @emoji_file_path
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,48 @@
1
+ module EmojiRegex
2
+ class Maker
3
+ def initialize
4
+ @input_file_path = Fetcher.new.saved_path
5
+ @prev = -1
6
+ @prev_hex = ''
7
+ @left = ''
8
+ @ranges = []
9
+ end
10
+
11
+ def ranges
12
+ ranges =
13
+ File.open(@input_file_path).map do |line|
14
+ hex = line.to_i(16)
15
+
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
25
+ end
26
+
27
+ ranges
28
+ .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)
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,3 @@
1
+ module EmojiRegex
2
+ VERSION = '0.1.0'.freeze
3
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: emoji-regex
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Satoshi Ohmori
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-09-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.16.a
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.16.a
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Make regex for latest unicode emoji from http://www.unicode.org/Public/emoji/6.0/emoji-data.txt
84
+ email:
85
+ - sachin21dev@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rubocop.yml"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - LICENSE
95
+ - README.md
96
+ - Rakefile
97
+ - bin/setup
98
+ - emoji-regex.gemspec
99
+ - emoji_sorted.txt
100
+ - lib/emoji-regex.rb
101
+ - lib/emoji-regex/fetcher.rb
102
+ - lib/emoji-regex/maker.rb
103
+ - lib/emoji-regex/version.rb
104
+ homepage: https://github.com/sachin21/ruby-emoji-regex
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.5.2
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: Make regex for latest unicode emoji.
128
+ test_files: []