Skip to content

Instantly share code, notes, and snippets.

@kapkaev
Last active December 14, 2015 07:08
Show Gist options
  • Save kapkaev/5047736 to your computer and use it in GitHub Desktop.
Save kapkaev/5047736 to your computer and use it in GitHub Desktop.
simple qwerty
#encoding: utf-8
module Utils
module Qwerty
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
EN = %W(q w e r t y u i o p [ ] a s d f g h j k l ; ' \\ z x c v b n m , . ')
RU = %w(й ц у к е н г ш щ з х ъ ф ы в а п р о л д ж э ё я ч с м и т ь б ю)
EN_RU = Hash[EN.each_with_index.map{ |chr, idx| [chr, RU[idx]] }]
def qwerty_convert(raw_string)
word = ''
raw_string.chars.each do |char|
word += if char.ord == 92
'ё'
elsif EN_RU.include? char.downcase
EN_RU[char.downcase]
else
char
end
end
return word
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment