module ColognePhonetics::Rules
@api private
Public Class Methods
apply_to(string)
click to toggle source
# File lib/cologne_phonetics/rules.rb, line 10 def self.apply_to(string) string = string.downcase.tr('ÄÖÜ', 'äöü') # Ruby < 2.3 downcases ASCII characters only chars = [nil] + string.chars + [nil] chars.each_cons(3).map{ |prev_char, char, next_char| code_for(prev_char, char, next_char) }.join end
code_for(prev_char, char, next_char)
click to toggle source
# File lib/cologne_phonetics/rules.rb, line 18 def self.code_for(prev_char, char, next_char) @rules.each do |matcher, code| return code if matcher.call(prev_char, char, next_char) end debug_info "Cologne Phonetics: No rule for '#{char}' (prev: '#{prev_char}', next: '#{next_char}')" nil end
debug_info(message)
click to toggle source
# File lib/cologne_phonetics/rules.rb, line 26 def self.debug_info(message) return unless ColognePhonetics.debug $stderr.puts message # rubocop:disable StderrPuts end
define(&block)
click to toggle source
# File lib/cologne_phonetics/rules.rb, line 6 def self.define(&block) @rules = DSL.new(&block).rules end