<repo_name>kirubiel/learn_ruby<file_sep>/03_simon_says/simon_says.rb
#write your code here
def echo(simon_said)
    simon_said
end

def shout(simon_said)
    simon_said.upcase
end

def repeat(simon_said, times = 2)
    ((simon_said + ' ') * times).strip
end

def start_of_word(simon_said, no_of_chars = 1)
    simon_said[0, no_of_chars]
end

def first_word(simon_said)
    simon_said.split.first
end

def titleize(simon_said)
    split_word = simon_said.split
    split_word.each_with_index do |word, i|
        if(not((split_word[i] == 'and' or
            word == 'over' or
            word == 'the') and 
            split_word.index(word) > 0))
           
            split_word[i] = word.capitalize
        end
    end
    split_word.join(' ')
end<file_sep>/01_temperature/temperature.rb
#write your code here
def ftoc (fahrenheit)
    (fahrenheit - 32) * (5.0/9.0)
end

def ctof (celsius)
    (celsius * (9.0 / 5.0)) + 32
end<file_sep>/05_book_titles/book.rb
class Book
# write your code here
    def title
        @title
    end

    def title=(title)
        conjs_and_prepos = ["and", "in", "the", "of", "a", "an"]
        split_title = title.split
        split_title.map! {|word|
            if conjs_and_prepos.index(word) and word != split_title[0]
                word = word
            else
                word = word.capitalize
            end
        }
        split_title = split_title.join(' ')
        @title = split_title
    end
end<file_sep>/04_pig_latin/pig_latin.rb
#write your code here
def translate(word)
    split_word = word.split

    vowels_regex = /^[aieou]/
    two_consonants = /\A[^aieou]{2}/
    three_consonants = /\A[^aieou]{3}/

    split_word.map! {|word|
        if vowels_regex.match(word)
            word << "ay"
        elsif not(vowels_regex.match(word)) and word[1] == "u"
            consonant_letter = word[0,2]
            word = word.sub(word[0,2], "")
            word << consonant_letter + "ay"
        elsif three_consonants.match(word)
            consonant_letter = word[0,3]
            word = word.sub(word[0,3], "")
            word << consonant_letter + "ay"
        elsif two_consonants.match(word)
            if word[2] == "u"
                consonant_letter = word[0,3]
                word = word.sub(word[0,3], "")
                word << consonant_letter + "ay"
            else
                consonant_letter = word[0,2]
                word = word.sub(word[0,2], "")
                word << consonant_letter + "ay" 
            end
        else
            consonant_letter = word.slice(0)
            word = word.sub(word[0], "")
            word << consonant_letter + "ay"
        end
    }

    split_word.join(" ")
end<file_sep>/02_calculator/calculator.rb
#write your code here
def add(a, b)
    a + b
end

def subtract(a, b)
    a - b
end

def sum(arr)
    total = 0
    arr.each do |item|
        total += item
    end
    total
end