class ColognePhonetics::Rules::DSL

Attributes

rules[R]

Public Class Methods

new(&block) click to toggle source
# File lib/cologne_phonetics/rules.rb, line 34
def initialize(&block)
  @rules = []
  instance_exec(&block)
end

Public Instance Methods

change(chars, to:, before: nil, not_before: nil, after: nil, not_after: nil, initial: nil) click to toggle source
# File lib/cologne_phonetics/rules.rb, line 39
def change(chars, to:, before: nil, not_before: nil, after: nil, not_after: nil, initial: nil)
  matcher = ->(prev_char, char, next_char){
    return unless chars.include?(char)
    return if initial && prev_char
    return if before && (!next_char || !before.include?(next_char))
    return if not_before && next_char && not_before.include?(next_char)
    return if after && (!prev_char || !after.include?(prev_char))
    return if not_after && prev_char && not_after.include?(prev_char)
    true
  }
  @rules << [matcher, to]
end