Class: GitHaiku

Inherits:
Object
  • Object
show all
Defined in:
lib/git_haiku.rb

Instance Method Summary collapse

Constructor Details

#initializeGitHaiku

Returns a new instance of GitHaiku.



8
9
10
11
# File 'lib/git_haiku.rb', line 8

def initialize
  @dict = []
  File.open('./dictionary.txt').each {|word| @dict << word}
end

Instance Method Details

#get_n_syllable_word(n) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# 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

#runObject



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/git_haiku.rb', line 13

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(" ")}")
  # p haiku_msg
  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