Permalink
Browse files

cleaned up pig latin.

  • Loading branch information...
1 parent f27f4cb commit 7cf81e9d0f059ece31e19ac5a4790c04c241aa4c @mspwong committed Aug 20, 2011
Showing with 5 additions and 3 deletions.
  1. +5 −3 app/models/why_nots/pig_latin.rb
@@ -3,13 +3,15 @@ class WhyNots::PigLatin
def self.translate(text)
text.split(" ").inject("") do |memo, token|
word = token.downcase.gsub(/[^a-z ]/, '')
- pig_latin_ending = "ay "
- pig_latin_word = word[1, token.length] << token.first << pig_latin_ending
+ pig_latin_word = word[1, token.length] << token.first << SUFFIX
pig_latin_word.capitalize! if token.first == token.first.capitalize
- punctuations = token[pig_latin_word.length-pig_latin_ending.length, token.length]
+ punctuations = token[pig_latin_word.length-SUFFIX.length, token.length]
pig_latin_word.chop! << punctuations unless punctuations.blank?
memo << pig_latin_word
end.strip
end
+private
+ SUFFIX = "ay "
+
end

0 comments on commit 7cf81e9

Please sign in to comment.