module RecordCache::Strategy::Util::Collator

StringCollator uses the Rails transliterate method for collation

Public Class Methods

clear() click to toggle source
# File lib/record_cache/strategy/util.rb, line 109
def self.clear
  @collated.each { |string| string.send(:remove_instance_variable, :@rc_collated) }
  @collated.clear
end
collate(string) click to toggle source
# File lib/record_cache/strategy/util.rb, line 114
def self.collate(string)
  collated = string.instance_variable_get(:@rc_collated)
  return collated if collated
  normalized = ActiveSupport::Multibyte::Unicode.normalize(ActiveSupport::Multibyte::Unicode.tidy_bytes(string || ''), :c).mb_chars
  collated = I18n.transliterate(normalized).downcase.mb_chars
  # transliterate will replace ignored/unknown chars with ? the following line replaces ? with the original character
  collated.chars.each_with_index{ |c, i| collated[i] = normalized[i] if c == '?' } if collated.index('?')
  # puts "collation: #{string} => #{collated.to_s}"
  string.instance_variable_set(:@rc_collated, collated)
  @collated << string
  collated
end