lib/translitter.rb in translitter-1.0.0 vs lib/translitter.rb in translitter-1.1.0

- old
+ new

@@ -32,17 +32,19 @@ "ů" => "u", "Ű" => "U", "ű" => "u", "Ų" => "U", "ų" => "u", "Ŵ" => "W", "ŵ" => "w", "Ŷ" => "Y", "ŷ" => "y", "Ÿ" => "Y", "Ź" => "Z", "ź" => "z", "Ż" => "Z", "ż" => "z", "Ž" => "Z", "ž" => "z" }.freeze - def initialize(default_rules: true, custom_rules: {}) + def initialize(default_rules: true, custom_rules: {}, replacement: "?") @rules = {} @rules.merge!(DEFAULT_RULES) if default_rules @rules.merge!(custom_rules) + + @replacement = replacement end - def transliterate(str, replacement: "?") + def transliterate(str, replacement: @replacement) str.gsub(/[^\x00-\x7f]/u) do |char| - @rules[char] || replacement + @rules[char] || replacement || char end end end