Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/layout_convert.rb
Overview
Mix-in necessary methods to make layout swap available
Constant Summary collapse
- LAYOUTS =
{ lat: %q!qwertyuiop[]asdfghjkl;'zxcvbnm,./QWERTYUIOP{}ASDFGHJKL:"ZXCVBNM<>?!.scan(/./), cyr: %q!йцукенгшщзхъфывапролджэячсмитьбю.ЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮ,!.scan(/./) }
- LANG =
{ lat: ('a'..'z').to_a + ('A'..'Z').to_a, cyr: ('а'..'я').to_a + ('А'..'Я').to_a }
- SPLIT_REGEX =
/[a-zA-Zа-яА-Я\[\];',\.\/{}:"<>?]+/
Instance Method Summary collapse
-
#cyrillic? ⇒ Boolean
Detect whether the given string is cyrillic.
-
#cyrillish? ⇒ Boolean
Detect whether the given string has more cyrillic letters.
-
#latin? ⇒ Boolean
Detect whether the given string is latin.
-
#latinish? ⇒ Boolean
Detect whether the given string has more latin letters.
-
#mixed? ⇒ Boolean
Detect whether the given string has both latin and cyrillic letters.
-
#swap_layout ⇒ Object
Swap the layout.
Instance Method Details
#cyrillic? ⇒ Boolean
Detect whether the given string is cyrillic
21 22 23 |
# File 'lib/layout_convert.rb', line 21 def cyrillic? guess_layout.equal?(:cyr) end |
#cyrillish? ⇒ Boolean
Detect whether the given string has more cyrillic letters
54 55 56 |
# File 'lib/layout_convert.rb', line 54 def cyrillish? !self.latinish? end |
#latin? ⇒ Boolean
Detect whether the given string is latin
27 28 29 |
# File 'lib/layout_convert.rb', line 27 def latin? guess_layout.equal?(:lat) end |
#latinish? ⇒ Boolean
Detect whether the given string has more latin letters
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/layout_convert.rb', line 40 def latinish? latin_count = cyrillic_count = 0 split_words.each do |word| if word.latin? latin_count+=1 else cyrillic_count+=1 end end latin_count > cyrillic_count end |
#mixed? ⇒ Boolean
Detect whether the given string has both latin and cyrillic letters
34 35 36 |
# File 'lib/layout_convert.rb', line 34 def mixed? guess_layout.equal?(:mixed) end |
#swap_layout ⇒ Object
Swap the layout
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/layout_convert.rb', line 60 def swap_layout if self.latinish? || self.cyrillish? split_words.map do |word| layout_map = set_layout word word.scan(/./).map do |ch| layout_map[ch].nil? ? ch : layout_map[ch] end.join end.join ' ' end end |