Created
December 4, 2013 16:44
-
-
Save justuseapen/7790910 to your computer and use it in GitHub Desktop.
This file contains 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
require 'pry' | |
class PigLatinTranslation | |
def initialize(phrase) | |
@phrase = phrase | |
end | |
#provide the pig latin translation | |
def translate | |
new_phrase = [] | |
words.each do |word| | |
if starts_with_vowel?(word) == true | |
new_phrase << word + "way" | |
else | |
word = word+word.chr.downcase + "ay" | |
new_phrase << word[1,word.size-1] | |
end | |
end | |
new_phrase.join(" ") | |
end | |
private | |
#an array of words in the phrase | |
def words | |
@phrase.split | |
end | |
def starts_with_vowel?(word) | |
if word[0].downcase == "a" | |
return true | |
elsif word[0].downcase == "e" | |
return true | |
elsif word[0].downcase == "i" | |
return true | |
elsif word[0].downcase == "o" | |
return true | |
elsif word[0].downcase == "u" | |
return true | |
else | |
return false | |
end | |
end | |
end | |
test = PigLatinTranslation.new"This is a test phrase" | |
puts test.translate |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment