-
Notifications
You must be signed in to change notification settings - Fork 11
/
passive_finder.rb
executable file
·52 lines (33 loc) · 1.02 KB
/
passive_finder.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
topics = Dir.glob('./**/*.html*')
output_file = './passives.txt'
reg = /(are|were|been|have|has|have)( \w+)? \w+e[dn]/m
passives = []
passive_lines = []
File.open(output_file, "w") { |file| file << "Passives:" }
def render_match_data match_data, file
file << "\n\tTopic path: #{match_data[:topic]}; line number: #{match_data[:line_number]}"
file << "\n\t\t#{match_data[:line]} "
end
topics.each do |topic_path|
topic_lines = File.open(topic_path, 'r')
topic_lines.each_with_index do |line, i|
matches = line.scan reg
matches.each do |m|
match_data = {
topic: topic_path,
line_number: i+1,
line: line,
match: m
}
passives << match_data
File.open(output_file, "a") do |file|
render_match_data match_data, file
end
end
passive_lines << line if matches.length > 0
end
if ARGV[0] && ARGV[0].to_i.to_s == ARGV[0]
break if passives.length > ARGV[0].to_i
end
end
puts "passives: #{passives.length}"