Module: RecordCache::Strategy::Util::Collator
- Defined in:
- lib/record_cache/strategy/util.rb
Overview
StringCollator uses the Rails transliterate method for collation
Class Method Summary collapse
Class Method Details
.clear ⇒ Object
92 93 94 95 |
# File 'lib/record_cache/strategy/util.rb', line 92 def self.clear @collated.each { |string| string.send(:remove_instance_variable, :@rc_collated) } @collated.clear end |
.collate(string) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/record_cache/strategy/util.rb', line 97 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 |