/vendor/plugins/salty_slugs/lib/salty_slugs/transliteration.rb
Ruby | 60 lines | 42 code | 7 blank | 11 comment | 2 complexity | d77484e54e0e8601fde821a24d3a0245 MD5 | raw file
- # encoding: utf-8
- module SaltySlugs
- # Russian transliteration
- #
- # ?????????????? ??? ???? ???????? ????????
- module Transliteration
- extend self
-
- # Transliteration heavily based on rutils gem by Julian "julik" Tarkhanov and Co.
- # <http://rutils.rubyforge.org/>
- # Cleaned up and optimized.
-
- LOWER = {
- "?"=>"i","?"=>"g","?"=>"yo","?"=>"#","?"=>"e",
- "?"=>"yi","?"=>"a","?"=>"b",
- "?"=>"v","?"=>"g","?"=>"d","?"=>"e","?"=>"zh",
- "?"=>"z","?"=>"i","?"=>"y","?"=>"k","?"=>"l",
- "?"=>"m","?"=>"n","?"=>"o","?"=>"p","?"=>"r",
- "?"=>"s","?"=>"t","?"=>"u","?"=>"f","?"=>"h",
- "?"=>"ts","?"=>"ch","?"=>"sh","?"=>"sch","?"=>"'",
- "?"=>"y","?"=>"","?"=>"e","?"=>"yu","?"=>"ya"
- }.freeze
-
- UPPER = {
- "?"=>"G","?"=>"YO","?"=>"E","?"=>"YI","?"=>"I",
- "?"=>"A","?"=>"B","?"=>"V","?"=>"G",
- "?"=>"D","?"=>"E","?"=>"ZH","?"=>"Z","?"=>"I",
- "?"=>"Y","?"=>"K","?"=>"L","?"=>"M","?"=>"N",
- "?"=>"O","?"=>"P","?"=>"R","?"=>"S","?"=>"T",
- "?"=>"U","?"=>"F","?"=>"H","?"=>"TS","?"=>"CH",
- "?"=>"SH","?"=>"SCH","?"=>"'","?"=>"Y","?"=>"",
- "?"=>"E","?"=>"YU","?"=>"YA",
- }.freeze
- # Transliterate a string with russian characters
- #
- # ?????????? ??????, ? ??????? ??? ????? ???????? ???????? ???????? ?? ??????? ?? ???????? ????????
- def transliterate(str)
- chars = str.split(//)
-
- result = ""
- chars.each_with_index do |char, index|
- if UPPER.has_key?(char) && LOWER.has_key?(chars[index+1])
- # combined case
- result << UPPER[char].downcase.capitalize
- elsif UPPER.has_key?(char)
- result << UPPER[char]
- elsif LOWER.has_key?(char)
- result << LOWER[char]
- else
- result << char
- end
- end
- return result
- end
- end
- end