-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwork.rb
52 lines (44 loc) · 1.07 KB
/
work.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
43
44
45
46
47
48
49
50
51
52
require_relative 'line'
class Work
attr_reader :lines, :rhymed_word_collection, :seuss_score
def initialize(args)
@title = args.fetch(:title)
@author = args.fetch(:author)
@lines_str = args.fetch(:lines)
@lines = args.fetch(:lines).map { |line| Line.new(line)}
@rhymed_word_collection = []
find_rhymes
calc_score
end
def calc_score
rhymed_word_count = 0
total_word_count = 0
lines.each do |line|
total_word_count += line.words.length
rhymed_word_count += line.words.count { |word| word.rhymed == true }
end
rhymed_word_count / total_word_count
end
def find_rhymes
comp_cuplets
end
def comp_cuplets
line_a = lines[0]
i = 1
while i < lines.length do
wrd1 = line_a.words.last
wrd2 = lines[i].words.last
if wrd1.compare(wrd2)
@rhymed_word_collection << [wrd1, wrd2]
end
line_a = lines[i]
i += 1
end
end
def comp_abab_scheme
end
def to_s
output_str = "#{title}\n#{author}\n"
lines.map { |line| line.description }.join("\n")
end
end