Module: Unicode::Confusable
- Defined in:
- lib/unicode/confusable.rb,
lib/unicode/confusable/index.rb,
lib/unicode/confusable/constants.rb
Constant Summary collapse
- INDEX =
Marshal.load(Gem.gunzip(File.binread(INDEX_FILENAME)))
- VERSION =
"1.2.0".freeze
- UNICODE_VERSION =
"10.0.0".freeze
- DATA_DIRECTORY =
File.(File.dirname(__FILE__) + '/../../../data/').freeze
- INDEX_FILENAME =
(DATA_DIRECTORY + '/confusable.marshal.gz').freeze
Class Method Summary collapse
Class Method Details
.confusable?(string1, string2) ⇒ Boolean
7 8 9 |
# File 'lib/unicode/confusable.rb', line 7 def self.confusable?(string1, string2) skeleton(string1) == skeleton(string2) end |
.skeleton(string) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/unicode/confusable.rb', line 11 def self.skeleton(string) require_relative 'confusable/index' unless defined? ::Unicode::Confusable::INDEX UnicodeNormalize.normalize( UnicodeNormalize.normalize(string, :nfd).each_codepoint.map{ |codepoint| INDEX[codepoint] || codepoint }.flatten.pack("U*"), :nfd ) end |