-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhaiku.rb
42 lines (37 loc) · 843 Bytes
/
haiku.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#Dependancies
require 'csv'
require_relative 'Ruby-Syllable-Counter/syllablecount'
#Class
class Haiku
@file
def initialize
puts "Making a haiku\n-------------------\n\n"
filename = "words.csv"
@file = CSV.read(filename)
puts make_poem+"\n---------------------"
end
def build_line(size)
i = 0
line = String.new
while i < size do
new_word = fetch_random_word.downcase
line << new_word << " "
i += get_syllable_count(new_word)
# puts get_syllable_count(new_word)
end
return line
end
def make_poem
return build_line(5) +"\n" + build_line(7) +"\n"+ build_line(5) +"\n"
end
def get_syllable_count(word)
#count vowels aeiou
@word = word
return @word.syllable_count
end
def fetch_random_word
wordRow = 1 + rand(10000)
return "#{@file[wordRow].join("''")}"
end
end
haiku = Haiku.new