Last active
December 14, 2015 07:08
-
-
Save kapkaev/5047736 to your computer and use it in GitHub Desktop.
simple qwerty
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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