Created
October 14, 2015 23:30
-
-
Save martin2110/1f292d249a05ca859ee3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def initialize | |
require 'pp' | |
@word_count = 0 | |
sentence = sentence_to_arr("I The greatest gift of life is friendship, and I have received it.") | |
puts speak_goat(sentence) | |
end | |
def speak_goat(sentence) | |
sentence.each_with_index do | word, i | | |
sentence[i] = transform_word(word) | |
end | |
sentence.join(' ') | |
end | |
def sentence_to_arr(sentence) | |
sentence.split(/\s+/) | |
end | |
def begins_with_consonant?(word) | |
consonant?(word[0].downcase) | |
end | |
def ends_with_punctuation?(word) | |
punctuation?(word[-1]) | |
end | |
def punctuation?(char) | |
char =~ /[[:punct:]]/ | |
end | |
def consonant?(char) | |
['a','e','i','o','u'].include?(char.downcase) | |
end | |
def transform_word(word) | |
@word_count += 1 | |
punctuation = '' | |
first_char = '' | |
char = word.split(//) | |
if ends_with_punctuation?(word) | |
punctuation = char.pop | |
end | |
if begins_with_consonant?(word) | |
first_char = char.shift | |
else | |
end | |
char = char.join("") | |
char + first_char + 'ma' + ('a'* @word_count ) + punctuation | |
end | |
end | |
GoatLatin.new |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment