rot13 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rot13.rb +4 -3
- metadata +1 -1
data/lib/rot13.rb
CHANGED
@@ -6,11 +6,12 @@ class Rot13
|
|
6
6
|
|
7
7
|
def self.rotate(s,deg=13)
|
8
8
|
|
9
|
-
a = (
|
9
|
+
a = ('a'..'z').map.with_index{|x,i| [x.chr,i] }
|
10
10
|
|
11
11
|
r = s.split(//).map do |x|
|
12
|
-
item = a.assoc(x)
|
13
|
-
item ? a.rotate(deg)[item.last].first : x
|
12
|
+
item = a.assoc(x.downcase)
|
13
|
+
c = item ? a.rotate(deg)[item.last].first : x
|
14
|
+
x == x.downcase ? c : c.upcase
|
14
15
|
end
|
15
16
|
|
16
17
|
r.join
|