class GitHaiku

Public Class Methods

new() click to toggle source
# File lib/git_haiku.rb, line 8
def initialize
        @dict = []
        file_path = File.join( File.dirname(__FILE__), '/assets/dictionary.txt')
        File.open(file_path).each {|word| @dict << word}
end

Public Instance Methods

get_n_syllable_word(n) click to toggle source
# File lib/git_haiku.rb, line 26
def get_n_syllable_word(n)
        n_syl_words = []
        syllable_count = 0


        until syllable_count == n
                rand_word = @dict.sample
                this_word_syllables = Lingua::EN::Syllable.syllables(rand_word)

                if (this_word_syllables + syllable_count) <= n
                        n_syl_words << rand_word.strip
                        n_syl_words
                        syllable_count += this_word_syllables
                end
        end

        n_syl_words
end
run() click to toggle source
# File lib/git_haiku.rb, line 14
def run
        haiku_msg = get_n_syllable_word(5).join(" ")
        haiku_msg.concat("; #{get_n_syllable_word(7).join(" ")}")
        haiku_msg.concat("; #{get_n_syllable_word(5).join(" ")}")
        git_msg = "git commit -m '#{haiku_msg}'"
        git_output = "git commit -m"
        print git_output.concat(" '#{haiku_msg}'".colorize(:red))
        puts
        system(git_msg)

end