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
|
# File 'lib/tzotchevsrt.rb', line 14
def parse_file(sub_file)
hash_with_sol = Hash.new(0)
max_sym_line = 0
avr_sym = 0.00
avr_sym_sentence = 0.00
sek_time = 0.00
sub_count = 0
File.open(sub_file, "r") do |file|
file.each_line do |line|
if line.match(/--> /)
sek_time += seconds_time(line)
sub_count += 1
end
if line.match( /[[[:upper:]][[:lower:]]]/)
hash_with_sol["number_of_words"] += line.gsub(/[[:punct:]]/, '').split.size
hash_with_sol["number_of_symbols"] += line.split(/[[:punct:]]/).size - 1 hash_with_sol["number_of_lines"] += 1
if hash_with_sol["max_symbols_per_line"] < line.split(/[[:punct:]]/).size - 1
hash_with_sol["max_symbols_per_line"] = line.split(/[[:punct:]]/).size - 1
end
hash_with_sol["number_of_sentences"] += line.split(/[^\.?!][\.?!]/).size - 1
end
end
end
avr_sym = hash_with_sol["number_of_symbols"].to_f/ hash_with_sol["number_of_lines"].to_f
hash_with_sol["average_symbols_per_line"] = avr_sym.round(2)
avr_sym_sentence = hash_with_sol["number_of_symbols"].to_f / hash_with_sol["number_of_sentences"].to_f
hash_with_sol["average_symbols_per_sentence"] = avr_sym_sentence.round(2)
hash_with_sol["duration"] = sek_time.round()
hash_with_sol["average_duration"] = (sek_time.round / sub_count).round(2)
return hash_with_sol
end
|