File tree Expand file tree Collapse file tree 2 files changed +61
-0
lines changed Expand file tree Collapse file tree 2 files changed +61
-0
lines changed Original file line number Diff line number Diff line change 1+ def translate ( input )
2+ vowel = "aeiouAEIOU"
3+ output = ""
4+ punct_check = /[[:punct:]]/ . match ( input )
5+ words = [ ]
6+
7+ if punct_check
8+ letters = input . split ( "" )
9+ wbuild = ""
10+ letters . each do |c |
11+ if /\w / . match ( c )
12+ wbuild += c
13+ else
14+ words . push ( wbuild ) if wbuild != ""
15+ words . push ( c ) if c != ""
16+ wbuild = ""
17+ end
18+ end
19+ else
20+ words = input . split ( " " )
21+ end
22+
23+ words . each do |term |
24+ if /\w / . match ( term ) == nil
25+ output += term
26+ next
27+ end
28+
29+ cap = false
30+ if /[[:upper:]]/ . match ( term [ 0 ] )
31+ cap = true
32+ end
33+ term = term . downcase
34+ term_letters = term . split ( "" )
35+
36+ while !vowel . include? ( term_letters [ 0 ] )
37+ if term_letters [ 0 ] + term_letters [ 1 ] == "qu"
38+ term_letters . push ( term_letters . shift )
39+ end
40+ term_letters . push ( term_letters . shift )
41+ end
42+
43+ term_letters [ 0 ] . upcase! if cap == true
44+ if punct_check
45+ output += term_letters . join ( "" ) + "ay"
46+ else
47+ output += term_letters . join ( "" ) + "ay" + " "
48+ end
49+ end
50+
51+ return output . strip
52+ end
Original file line number Diff line number Diff line change 6969 # * write a test asserting that capitalized words are still capitalized (but with a different initial capital letter, of course)
7070 # * retain the punctuation from the original phrase
7171
72+ it "capitalized words are still capitalized" do
73+ s = translate ( "hello World" )
74+ s . should == "ellohay Orldway"
75+ end
76+
77+ it "retain punctuation from original phrase" do
78+ s = translate ( "Hello, World!" )
79+ s . should == "Ellohay, Orldway!"
80+ end
7281end
You can’t perform that action at this time.
0 commit comments