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.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
8 9 10 |
# File 'lib/unicode/confusable.rb', line 8 def self.confusable?(string1, string2) skeleton(string1) == skeleton(string2) end |
.skeleton(string) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/unicode/confusable.rb', line 12 def self.skeleton(string) require_relative 'display_width/index' unless defined? ::Unicode::Confusable::INDEX UnicodeNormalize.normalize( UnicodeNormalize.normalize(string, :nfd).each_codepoint.map{ |codepoint| INDEX[codepoint] || codepoint }.flatten.pack("U*"), :nfd ) end |