lib/prawn/emoji/index.rb in prawn-emoji-2.0.0 vs lib/prawn/emoji/index.rb in prawn-emoji-2.0.1
- old
+ new
@@ -1,19 +1,34 @@
+# frozen_string_literal: true
+
module Prawn
module Emoji
class Index
- def unicodes
- @unicodes ||= YAML.load Emoji.root.join('emoji', 'index.yml').read
+ EXCLUSION_CHARS = '1234567890#*'.freeze
+
+ attr_reader :codepoints
+
+ def initialize
+ @codepoints = load_emoji_codepoints
end
- def unicodes_regexp
- @unicodes_regexp ||= build_unicodes_regexp
+ def to_regexp
+ @regexp ||= build_regexp
end
private
- def build_unicodes_regexp
- Regexp.compile unicodes.map { |unicode| "\\u{#{unicode.split('-').join(' ')}}" }.join('|')
+ def build_regexp
+ Regexp.new(codepoints.map { |codepoint| unicode(codepoint) }.join('|'))
+ end
+
+ def load_emoji_codepoints
+ codepoints = YAML.load_file(Emoji.root.join('emoji', 'index.yml'))
+ codepoints.reject { |codepoint| /#{unicode(codepoint)}/ =~ EXCLUSION_CHARS }
+ end
+
+ def unicode(codepoint)
+ "\\u{#{codepoint.split('-').join(' ')}}"
end
end
end
end