-
Notifications
You must be signed in to change notification settings - Fork 0
/
processor.rb
64 lines (42 loc) · 976 Bytes
/
processor.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
def readFile(file)
open_file=File.open(file)
file=open_file.read
open_file.close()
file
end
readtext = readFile("file1.txt")
def xter_count (text)
text.length
end
def word_count(text)
text.split(" ").count
end
def line_count(text)
text.lines.count
end
def para_count(text)
text.split("\n\n").count
end
def sentence_count(text)
text.split(/\.|\?|\!/).count
end
def ave_words_sent(text)
word_count(text)/sentence_count(text)
end
def ave_sent_per_parg(text)
sentence_count(text)/para_count(text)
end
print "number of characters:"
puts xter_count(readtext)
print "number of words:"
puts word_count(readtext)
print "Number of lines:"
puts line_count(readtext)
print "Number of paragraphs"
puts para_count(readtext)
print "Number of sentences:"
puts sentence_count(readtext)
print "Average number of words in a sentence:"
puts ave_words_sent(readtext)
print"Average number of sentences per paragraph:"
puts ave_sent_per_parg(readtext)