lib/unicode/confusable.rb in unicode-confusable-1.2.0 vs lib/unicode/confusable.rb in unicode-confusable-1.3.0

- old
+ new

@@ -14,8 +14,18 @@ UnicodeNormalize.normalize(string, :nfd).each_codepoint.map{ |codepoint| INDEX[codepoint] || codepoint }.flatten.pack("U*"), :nfd ) end + + def self.list(char, partial_mapping_allowed = true) + require_relative 'confusable/index' unless defined? ::Unicode::Confusable::INDEX + codepoint = char.codepoints.first or raise ArgumentError, "no data given to Unicode::Confusable.list" + if partial_mapping_allowed + INDEX.select{ |k,v| v == codepoint || v.is_a?(Array) && v.include?(codepoint) }.keys.map{ |codepoint| [codepoint].pack("U*") } + else + INDEX.select{ |k,v| v == codepoint }.keys.map{ |codepoint| [codepoint].pack("U") } + end + end end end